LookupEvent Generics and Wildcard [rawtype] best usage pattern suggestion
"bruehlicke" <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
To answer myself, there is actually a critical difference between <?> and <? extends Object> as the first is reifiable whereas the second is not. See http://stackoverflow.com/questions/14346622/list-vs-list-extends-object
This is critical as my code is using "instanceof" and hence need the <?>.
Code:
@Override
public void resultChanged(LookupEvent lookupEvent) {
Lookup.Result<?> r = (Lookup.Result) lookupEvent.getSource();
Collection<?> c = r.allInstances();
if (!c.isEmpty()) {
for (Object o : c) {
if (o instanceof XYZ) {
This is at least my understanding. Correct me if I am wrong.