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 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.
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?
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.