英文:
How to create a differentiated marker class hierarchy
问题
我有一个情况,其中我有一个基本接口(X
),一个可更新的接口(updatableX
),和一个不可更新的接口(frozenX
)。
frozenX
的实现应该实现 hashCode() 和 equals() 方法,以便适用于哈希映射和类似的集合。
frozenX
可以是一个标记接口。
updatableX
的实现不会显式地实现 hashCode() 或 equals() 方法,因为用于区分一个 updatableX
实例与另一个实例的值是 updatableX
中可更新的值。
X
具有所有其他通用方法。
是否有可能定义 X
、updatableX
和 frozenX
,以确保没有实现 Y
同时实现 updatableX
和 frozenX
?
英文:
I have a case where I have a base interface (X
), an updatable interface (updatableX
), and a nonUpdatableInterface (frozenX
).
frozenX
implementations are expected to implement hashCode() and equals() methods so as to be suitable for use in hash maps and similar collections.
frozenX
may be a marker interface.
updatableX
implementations will not explicitly implement hashCode() or equals() as the values necessary to distinguish one X from another are the values that are updatable in updatableX
.
X
has all the other common methods.
Is it possible to define X
, updatableX
and frozenX
is such a way as to ensure that there are no implementations Y
such that Y
implements both updatableX
and frozenX
?
专注分享java语言的经验与见解,让所有开发者获益!
评论