我有两个类使用注释来定义字段和数据库列名之间的链接。除了它们定义的列名之外,这些类非常相似:
class TableA {
@ForeignName("IDTableA") // Column name in TableC referring to this TableA record
List<TableC> elements;
// Some other field definitions, common between TableA and TableB
// Some other field definitions, specific to TableA
}
class TableB {
@ForeignName("IDTableB") // Column name in TableC referring to this TableB record
List<TableC> elements;
// Some other field definitions, common between TableA and TableB
// Some other field definitions, specific to TableB
}
class TableC {
@LocalName("IDTableA")
TableA refA;
@LocalName("IDTableB")
TableB refB;
}
我想有一个超类,我可以给它"IDTableA/B"
常量。理想情况下是“类似”(我知道除了类型之外你不能给泛型提供任何东西,只是为了说明我的观点):
abstract class TableAB<IDName> {
@ForeignName(IDName)
List<TableC> elements;
// Field definitions common between TableA and TableB
}
class TableA extends TableAB<"IDTableA"> {
// Field definitions, specific to TableA
}
class TableB extends TableAB<"IDTableB"> {
// Field definitions, specific to TableB
}
这有可能吗?