eclipse and un-generics

A

Andreas Leitgeb

I'm working with a somewhat dated Version of eclipse, and I stumbled
over some "legacy"-bits in the eclipse-core libraries, especially
org.eclipse.core.runtime.IAdaptable.getAdapter(Class adapter)

Do I just have to live with it (and write non-generic code also
for the classes implementing IAdaptable - eventually with an
annotation that suppresses the warning), or is it something that
an eclipse-upgrade or some other trick in the implementing class
would solve?

My attempt to use Class<?> as argument type in the implementing
class failed, and I'm not sure I understand the deeper reasons of
why this has to fail. I.e. why it doesn't just see it as an override
instead of complaining about a bad overload.
 
J

Joshua Cranmer

My attempt to use Class<?> as argument type in the implementing
class failed, and I'm not sure I understand the deeper reasons of
why this has to fail. I.e. why it doesn't just see it as an override
instead of complaining about a bad overload.

While Class<?> is often treated as being the generic equivalent of
Class, they're not quite the same thing. Logically, "Class" means "a
class of anything", while "Class<?>" means "a class of some unknown type".

Indeed, if anything, "Class" is probably closer in typing terms to
"Class<Object>", although there are a slew of special rules to account
for the fact that "Class<Object>" is probably very rarely meant.
 
A

Andreas Leitgeb

Joshua Cranmer said:
While Class<?> is often treated as being the generic equivalent of
Class, they're not quite the same thing. Logically, "Class" means "a
class of anything", while "Class<?>" means "a class of some unknown type".

I see the relevance for e.g. List<?> versus List where the former (unlike
the latter) could not be add()ed an Object-typed item. I don't see, how it
could make a difference for Class<?> versus Class, of which no method takes
any "T"-typed arguments, nor do any methods of the "<T>"-parameterized
return-value-types (like e.g. Constructor<T>).
But then again, I do see, that the JLS just doesn't go that far into
analysis of where said:
Indeed, if anything, "Class" is probably closer in typing terms to
"Class<Object>", although there are a slew of special rules to account
for the fact that "Class<Object>" is probably very rarely meant.

I'll try on Monday (to be sure), but I really don't expect
(Class<Object> clazz) to be valid arguments for an overRIDE of
a superclass's method taking (Class clazz).

Anyway, I appreciate your response, making me aware that <?>
isn't semantically the closest to the bare type, afterall.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top