如何调用枚举的方法,这是另一个枚举

时间:2018-03-09 12:24:49

标签: java enums

我有三个枚举,一个是First,Second和Third,我想调用enum是First enum属性的方法。

enum First{
ACRE1("a","b","Second");
ACRE2("a","b","Third");

private final String name;
private final String secondName;
private final String thirdName;

private First(final thatName, final thatSecondName, final thatThirdName){
    this.name = thatName;
    this.name = thatSecondName;
    this.name = thatThirdName;
}

public String getThirdField(){
    return this.thirdName;
}
}

enum Second{
ABC("abc"),
CDE("cde");

private final String name;

private Second(final String name) {
    this.name = name;
}

@Override
public String toString() {
    return name;
}

public static List<String> getAllHeaders() {
    List<String> allHeadersList = Stream.of(Second.values())
                                 .map(Second::toString)
                                 .collect(Collectors.toList());
    return allHeadersList;
}
}

enum Third{
ABCD("abcd"),
CDEF("cdef");

private final String name;

private Second(final String name) {
    this.name = name;
}

@Override
public String toString() {
    return name;
}

public static List<String> getAllHeaders() {
    List<String> allHeadersList = Stream.of(Second.values())
                                 .map(Second::toString)
                                 .collect(Collectors.toList());
    return allHeadersList;
}
}

我想要的是:     first.getThirdField()。getAllHeaders 这里首先可以是ACRE1或ACRE2,具体取决于用户输入,但first.getThirdField()将返回一个字符串如何从该字符串调用该枚举?

0 个答案:

没有答案