IntelliJ/JDK 11: Cannot find symbol name() interface java.lang.annotation.Annotation

I have this simple code:

String tableName = MyEntity.class.getAnnotation( javax.persistence.Table.class ).name();

But IntelliJ underlines the fact that the method name() does not exist Cannot resolve method "name()".

I also get this error during the compilation:

Error:(29, 68) java: cannot find symbol
  symbol:   method name()
  location: interface java.lang.annotation.Annotation

I saw many example codes using this method, an example here: What am I missing?



As you can see here there is no name() function inside the Annotation interfaces

You probably need to cast it:

Table table = MyEntity.class.getAnnotation(javax.persistence.Table.class);
String tableName =;

Leave a Reply

Your email address will not be published. Required fields are marked *