aspose 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


Win a copy of Spring in Action this week in the Spring forum!
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: 29
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: 3647
    
  17

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: 29
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: 3647
    
  17

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about generic type