Get a Superclass from TypeElement without Generic?

I have a class:

public class StartPagePresenter extends AbstractPresenter<String> {
...
}

      

Using Java annotation processing I got TypeElement

for a class:

TypeElement startPagePresenterType = // get the TypeElement of StartPagePresenter

      

Now I need to get the superclass that is executed with

startPagePresenterType.getSuperclass();

      

Then I tried to check if the superclass is of the correct type:

if ( !startPagePresenterType.getSuperclass().toString().equals(
     AbstractPresenter.class.getCanonicalName()) ) {
 ...
}

      

Here's the problem: AbstractPresenter.class.getCanonicalName()

Leads to:

core.mvp.AbstractPresenter

      

and startPagePresenterType.getSuperclass().toString()

results in:

core.mvp.AbstractPresenter<java.lang.String>

      

When you compare these strings, they are never equal, although the superclasses are the same.

How do I get a superclass from a startPagePresenterType.getSuperclass()

non shared block?

+3


source to share


1 answer


I found the answer:

TypeMirror superClassTypeMirror = startPagePresenterType.getSuperclass();
TypeElement superClassTypeElement = 
            (TypeElement)((DeclaredType)superClassTypeMirror).asElement();

      



What is it! superClassTypeElement

that is, the TypeElement

superclass.

+7


source







All Articles