【发布时间】:2014-08-22 03:35:56
【问题描述】:
我有一个 bean ArtistEntityBean 扩展 GenericEntityBean:
public class ArtistEntityBean extends GenericEntityBean<Artist> {
public ArtistEntityBean() {
item = new Artist();
}
}
-
public abstract class GenericEntityBean<T extends IntEntity> implements Serializable {
protected T item;
public void init(Integer id){
item.setId(id);
}
}
-
public class Artist extends ArtistBaseEntity implements Comparable<Artist> {
...
}
-
public abstract class ArtistBaseEntity implements IntEntity {
...
}
-
public interface IntEntity {
Integer getId();
void setId(Integer id);
}
-
我试图在GenericEntityBean 类中放置尽可能多的代码,这就是为什么我想到使用接口以便能够设置item 的id。
这并不难,因为我在ArtistEntityBean 的构造函数中得到了一个NoSuchFieldError,我不知道为什么?
【问题讨论】:
-
GenericEntityBean 如何知道项目?它是一个父类
-
您在
GenericEntityBean中有item字段吗? -
NoSuchFieldError 是运行时异常,通常仅在您以某种方式弄乱类路径时才会发生(例如,在运行时使用旧版本的 .class)。
标签: java generics types interface