Tag: marker interfaces

为什么java注释?

我想问为什么java注释使用了这么多…我知道他们替换了例如jpa中的xml配置,但是为什么这种配置会被使用呢? 考虑这段代码: @Entity class Ent{ // some fields } //… somewhere in the other file far far away class NonEnt{ // whatever here } 现在,当我尝试将它放在持久化上下文中时,使用EntityManager的persist方法,我会在尝试持久化NonEnt实例时遇到运行时错误(更好的是获得编译错误)。 对我来说有明显的解决方案,强制实体实现一些无方法接口,而不是使用@Annotations。 但这在框架设计师中并不流行,这个解决方案的缺点是什么? 谢谢回答…