cou*_*ech 15 java annotations marker-interfaces
我想问为什么java注释使用了这么多...我知道他们替换了例如jpa中的xml配置,但为什么这种配置会被使用呢?考虑一下这段代码:
@Entity
class Ent{
// some fields
}
//... somewhere in the other file far far away
class NonEnt{
// whatever here
}
Run Code Online (Sandbox Code Playgroud)现在,当我尝试将其置于持久化上下文中时,使用EntityManager's persist方法,我会在尝试持久化NonEnt实例时遇到运行时错误(更好的是获得编译错误).对我来说有明显的解决方案,强制实体实现一些无方法接口,而不是使用@Annotations.但这在框架设计师中并不流行,这个解决方案的缺点是什么?Nee*_*aks 10
与标记接口相比,注释具有一些优点:
据说注释也不那么具有侵入性,但这一点是品味和有争议的问题.
也可以看看:
| 归档时间: |
|
| 查看次数: |
5052 次 |
| 最近记录: |