我有一个类Propositions
,它是类的数组列表
命题
:我想制作一棵树,其节点来自类
ConstituentSet
或 Proposition
。树上只有叶子来自
class Proposition
和所有内部节点都来自类
ConstituentSet
。
我不知道应该如何定义类型
ConstituentSet
类中的子级。如果我从类型定义
ConstituentSet
,我无法在此类型中设置我的叶子(因为它们是
来自 Proposition
),如果我从类型 Proposition
设置子项,
我无法设置我的内部节点。
public class ConstituentSet<T> {
protected ConstituentSet<T> child1, child2;
//OR
protected Proposition child1,child2;
}
public class Proposition {
private Property property;
private Rating rating;
private Type type;
private Serializable value;
}
最佳答案
让您的Propositions
和ConstituentSet
实现一个通用的接口(interface),然后从该接口(interface)的实例构成一棵树。
关于java - 两个不同类之间的类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17833132/