如何创建一个差异化的标记类层次结构

huangapple 未分类评论56阅读模式
英文:

How to create a differentiated marker class hierarchy

问题

我有一个情况,其中我有一个基本接口(X),一个可更新的接口(updatableX),和一个不可更新的接口(frozenX)。

frozenX 的实现应该实现 hashCode() 和 equals() 方法,以便适用于哈希映射和类似的集合。
frozenX 可以是一个标记接口。

updatableX 的实现不会显式地实现 hashCode() 或 equals() 方法,因为用于区分一个 updatableX 实例与另一个实例的值是 updatableX 中可更新的值。

X 具有所有其他通用方法。

是否有可能定义 XupdatableXfrozenX,以确保没有实现 Y 同时实现 updatableXfrozenX

英文:

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?

huangapple
  • 本文由 发表于 2020年7月29日 00:03:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/63138288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定