英文:
How to make generic type of specifically annotated class?
问题
我需要将一个接口泛型化,该接口是针对带有特定注释的类进行注释的,例如具有以下实体类
@Entity
@Audited
class Record {
private Long id;
private String something;
private String somethingElse;
}
该类使用Hibernate Envers进行审计,我想提供一个服务类,该类获取一些修订数据。类似以下方式:
public interface AuditRecordService<E extends Audited> {
//
}
我知道我可以修改Record
类以扩展一个抽象类,类似这样:
@Entity
@Audited
class Record extends RevisionedEntity {
...
这对我有效,但我想避免不必要的扩展,因为它已经使用了@Audited
注释。是否可能将此注释重用为泛型类型?
英文:
I need to generify an interface to a class that is annotated to a specific annotation, say having the following entity class
@Entity
@Audited
class Record {
private Long id;
private String something;
private String somethingElse;
}
which is audited with Hibernate Envers, I want to provide a service class that obtains some revision data. With something like
public interface AuditRecordService<E extends Audited> {
//
}
I know I can modify the Record
class to extend an abstract class, something like:
@Entity
@Audited
class Record extends RevisionedEntity {
...
This works for me, but I want to avoid unnecessary extension, since it's already annotated with @Audited
. Is it possible to reuse this annotation as a generic type?
答案1
得分: 0
Audited
是一个注解,而不是一种类型。注解不能被扩展,因此 AuditRecordService<E extends Audited>
的唯一可能实现将是 AuditRecordService<Audited>
,这将毫无用处。
英文:
Audited
is an annotation, not a type. Annotations cannot be extended, so the only possible implementation of AuditRecordService<E extends Audited>
would be AuditRecordService<Audited>
, which would be pretty useless.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论