casting - Java - Unchecked cast from Object to Map.Entry<String,String> -
i have "unchecked cast object map.entry" on "map.entry entry = (entry) o;"
i think ok , can put add suppress warning safely i'm not sure. here's code.
public abstract class webpath { protected hashtable<string, string> wp; public string get(string whatdoyouwant) { (object o : wp.entryset()) { map.entry<string, string> entry = (entry<string, string>) o; if (whatdoyouwant.equals(entry.getkey())) { return (string) entry.getvalue(); } } return null; } } thank everybody, have day !
the compiler doesn't when take instance , cast derived class. because have no guarantee that instance is derived class. if know better such in case, that's fine, not best practice in general.
your wp.entryset() returning set of map.entry. use map.entry! better still if you're not dropping generic types, should have:
for(map.entry<string, string> entry : wp.entryset()) { // ... } no need cast since know type is.
Comments
Post a Comment