Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Joe Vahabzadeh
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • 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?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic