File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A question about generic type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question about generic type" Watch "A question about generic type" New topic
Author

A question about generic type

Runrioter Wung
Greenhorn

Joined: Sep 03, 2011
Posts: 27
I enter a fragment of code: Vector<String> names = new Vector<>();I think it is right! But Eclipse told me that I should add the cast: Vector<String> names = new Vector<String>();Anybody tell me what's wrong?Thanks!
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3378
    
    9
It's perfectly fine. It sounds like Eclipse is just being grumpy. Is it giving you a warning, or isn't it letting you compile at all?
Runrioter Wung
Greenhorn

Joined: Sep 03, 2011
Posts: 27
Stephan van Hulst wrote:It's perfectly fine. It sounds like Eclipse is just being grumpy. Is it giving you a warning, or isn't it letting you compile at all?

yeah,I can't compile it,so I have to add that cast.
Jason Bullers
Greenhorn

Joined: Dec 27, 2011
Posts: 28

What version of Java are you working with? I believe being able to omit the String on the right side is new in Java 7. Maybe there's a problem with the language level settings in your IDE?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3378
    
    9
Note that it's not a cast. The correct term is generic type argument.

It sounds like your IDE uses an older source code version setting than 1.7. I don't use Eclipse, but look around in the project properties to see if you can edit the source code version.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A question about generic type
 
Similar Threads
can anybody explain the program?
protected variable of Vector
Combining fields from 2 resultsets in 1 vector
Merging rows with same ID together with dynamic headers with CSV
JTable, rowVector, addNotify()