java - Compilation (genericity) issues overriding Properties.putAll -
for javafx ui, implemented class observableproperties extends java.util.properties , enables listen changes of properties (in particular, localized texts of ui).
it works fine override putall method , having issues that.
first, properties extends hashtable<object,object>, expect able override
@override public void putall(map<object,object> that) but compile won't let me (saying i'm not overriding super method), have use
@override public void putall(map that) i want perform action on entries of that tried usual
for (map.entry entry : that.entryset()) but compiler tells me type mismatch: cannot convert element type object map.entry. however, second snippet
set<map.entry> set = that.entryset(); (map.entry : set); it compiles...
to sum up, know :
- why have remove bounds of
map<k,v>in signature - why first
forloop not compile whereas seems equivalent second one
thanks in advance !
you have signature of putall method wrong. override method hasttable signature must match, should be:
@override public synchronized void putall(map<? extends object, ? extends object> t) { } the ? extends object allows pass typed map method. if signature putall(map<object,object> t) able pass maps of type map<object,object>. passing map<string,string> example give error.
the first loop won't compile because that.entryset() returning set of type set<object>. loop won't convert object map.entry you.
the second loop works, type safety warnings, because you're telling compiler set of type set<map.entry> before pass loop.
Comments
Post a Comment