Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Generics and Annotations: Type-Safe

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!

like image 544
caarlos0 Avatar asked Apr 06 '12 18:04

caarlos0


1 Answers

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?

like image 81
John Farrelly Avatar answered Oct 25 '22 04:10

John Farrelly