Java Annotations Processor: Check if TypeMirror implements specific interface

前端 未结 1 797
攒了一身酷
攒了一身酷 2021-02-13 06:03

I\'m working with on a Java annotations processor. My annotation, @foo is used to mark field variables that can be read to a file or from a file during runtime. How

相关标签:
1条回答
  • 2021-02-13 06:27

    Instead of checking the direct supertypes, you should use Types.isAssignable to check if Serializable is one of the supertypes of the TypeMirror:

    TypeMirror serializable = elementUtil.getTypeElement("java.io.Serializable").asType();
    boolean isSerializable = typeUtil.isAssignable(tm, serializable);
    
    0 讨论(0)
提交回复
热议问题