• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Eclipse Indigo for Java EE, why no typechecking for paramaterized objects?

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The version I'm using, according to About Eclipse, is:


Ok, so, I found out that if I have an object (say a Map) with the Key type and Value type defined, but then do a get with the wrong object type, Eclipse doesn't complain.

That is, here's the sample code:


Why doesn't the last line give me a warning or error? I could've sworn that, when I used to use Eclipse for Java SE, that it would complain about that. Am I remembering this wrong? Is there some preference or setting that I have to use?
 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The signature of the Map#get() method is V get(Object) (and if you print it out, you get null, as expected). There is therefore no need for parameterisation of that method; if you precede it with
myMap.put("text", 123);
however, you get a compiler error.
 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, got it! Ok, so I WAS remembering it incorrectly.

Of course, in my sudden indignation, I furiously asked "Well, why the hell isn't the signature V get(K key) instead of V get(Object key)???"

Though I can actually see arguments for both . . . so my indignation ran out of steam real quick, and has settled down into mere irritable grumbling.
reply
    Bookmark Topic Watch Topic
  • New Topic