【发布时间】:2012-02-13 22:16:41
【问题描述】:
我正在尝试在 java 接口中继承以下参数(来自 Spring Data JPA 的示例,但问题通常是关于注释的参数):
public interface ItemRepository<T extends Item> extends BaseRepository<T> {
public final String type = null;
@Query("select distinct i from " + type + " i " +
"join i.tags t " +
"join fetch i.locale where t = ?1")
public List<T> findByTag(Tag t);
}
所以在继承的接口中我可以:
public interface EventRepository extends ItemRepository<Event> {
public final static String type = "Event";
}
但不幸的是,变量“type”的字符串值关联到变量的时间太晚了,所以在创建注解时,该值仍然为null。我可以强制编译器从子接口关联变量吗?
谢谢
【问题讨论】:
-
我相信这就是单例模式的用途。
-
但这些是接口,而不是类。你能详细说明一下吗?我很感兴趣! :)
标签: java inheritance annotations spring-data