gpt4 book ai didi

java - 如何匹配java枚举

转载 作者:行者123 更新时间:2023-12-03 23:04:20 26 4
gpt4 key购买 nike

我有一个这样的枚举:

public enum ChartType
{
TABLE(0, false), BAR(1, false), COLUMN(3, false)
private int type;
private boolean stacked;
ChartType(int type, boolean stacked)
{
this.type = type;
this.stacked = stacked;
}
public int getType()
{
return type;
}
public boolean isStacked()
{
return this.stacked;
}
}

我从请求中得到一个图表类型(int 值,如 0、1、3)并想要匹配的输入

最佳答案

类似的东西。不确定语法是否是 100%,但它演示了这个想法。

public ChartType getChartypeForValue(int value)
for(ChartType type : ChartType.values()){
if(type.getType() == value){
return type;
}
}
return null;
}

关于java - 如何匹配java枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28904113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com