Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Consider I have multiple Enums, each with different values, but all regarding to similar things:

@Getter
@RequiredArgsConstructor
public enum Dict implements Dictionary {

    VALUE1 ("Value1"),
    VALUE2 ("Value2");

    private final String name;
}

@Getter
@RequiredArgsConstructor
public enum Dict2 implements Dictionary {

    VALUE3 ("Value3"),
    VALUE4 ("Value4");

    private final String name;
}

...

Dict3 implements Dictionary{}
Dict4 implements Dictionary{}
Dict5 implements Dictionary{}

etc.

Now I have a method:

public SomeObject getObject(Enum objectType, String someString){
    if(ObjectType.Factory == objectType){
        return new SomeObject(Dict.valueOf(someString));
    } else if(ObjectType.Center == objectType){
        return new SomeObject(Dict2.valueOf(someString));
    }
    
    (more else ifs)...

    return new SomeObject(DictN.valueOf(someString));    
}

Is there a nice way to get the specific Dictionary type by Enum provided in a method? Hope I've made myself clear.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
366 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...