0

フィールドとデータベース列名の間のリンクを定義するために注釈を使用する 2 つのクラスがあります。これらのクラスは、定義する列名を除いて非常に似ています。

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"定数を与えることができるスーパークラスが欲しいです。理想的には「次のようなもの」です (Generics に型以外のものを指定できないことはわかっていますが、私の主張を説明するためだけに):

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
}

それはどういうわけか可能ですか?

4

1 に答える 1

2

いいえ、これは不可能です。IDName の部分は定数である必要があり、どのような場合でも String リテラルをジェネリック型として提供することはできません。

于 2013-09-05T12:51:37.470 に答える