6

I know that I can do something like:

public class AbstractDao<T extends Bean> {

}

In this case, Bean is an class or interface.

I was wondering if is there a way to do this with annotations, like:

public class AbstractDao<T extends javax.persistence.Entity> {

}

Is something like this possible?

Thanks in advance!

caarlos0
  • 20,020
  • 27
  • 85
  • 160

2 Answers2

4

Unfortunately, there is no inheritance in annotations, so it's not possible.

Have a look at the answers to the similar question here:

Why is not possible to extend annotations in Java?

Community
  • 1
  • 1
John Farrelly
  • 7,289
  • 9
  • 42
  • 52
4

No. The Java Language Specification says that type variables can only be constrained to extend / implement particular classes or interfaces. Since annotating a class does not cause the class to extend or implement a particular type, you can't constrain by annotation.

meriton
  • 68,356
  • 14
  • 108
  • 175