wood burning stoves 2.0*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse Indigo for Java EE, why no typechecking for paramaterized objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse Indigo for Java EE, why no typechecking for paramaterized objects?" Watch "Eclipse Indigo for Java EE, why no typechecking for paramaterized objects?" New topic
Author

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

Joe Vahabzadeh
Ranch Hand

Joined: Jan 05, 2005
Posts: 140
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

Joined: Oct 13, 2005
Posts: 38036
    
  22
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

Joined: Jan 05, 2005
Posts: 140
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Eclipse Indigo for Java EE, why no typechecking for paramaterized objects?
 
Similar Threads
unchecked cast exception from object to String[] conversion
EJB QL RETURNING ONLY THE FIRST RECORD OF THE TABLE
Map mock question
Null Values
Doubt regarding maps key type while bnding