Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 79528
379
  • 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.
 
You can't expect to wield supreme executive power just because
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic