• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

A question about generic type

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 14682
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 115
11
IntelliJ IDE Clojure Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 14682
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic