-2

我希望子类将特定的枚举值传递给父类extends,以便这些特定的枚举值将在某些注释中的父类中使用。以下是我真正想要实现的目标。

public enum SomeEnum {
    VAL1, VAL2;
}

public @interface SomeAnnotation {
    SomeEnum someValue();
}

//below starts all fuzzy things : I want a specific value of enum 
public class parent<FetchType> {// not sure what exactly should write between  < >

    // below,at someValue I want the specific enum passed by child , means
    // the value passed between < and > 
    @SomeAnnotation(someValue = null /* here  should be the specific enum value passed 
    as type parameter of this class */) 
    private String someString;
        //getter-setter
}
//as i said , for child1 , i need SomeEnum.VAL1 to be passed to parent and
// SomeEnum.VAL2 for child2.
public class child1 extends parent<SomeEnum.VAL1>{}
public class child2 extends parent<SomeEnum.VAL2>{}
4

1 回答 1

0

我会四处走动,建议你不需要Enumannotations但也许像下面这样?

interface NotEnum  {
  interface Val1 extends NotEnum {}
  interface Val2 extends NotEnum {}
}

class Parent<T extends NotEnum> {...}

class Child1 extends Parent<NotEnum.Val1> {...}
class Child2 extends Parent<NotEnum.Val2> {...}
于 2013-02-08T18:39:45.570 回答