Java接口字段到枚举列表
如何从不同类中的交换机访问这些字段?我需要为每个 LocationType 做一个 switch case。
@FunctionalInterface
public interface LocationType {
LocationType UNKNOWN = () -> "Unknown Location";
LocationType MERGE = () -> "Merge Location";
LocationType REGULAR = () -> "Regular Location";
LocationType MULTI = () -> "Multi Location";
LocationType ZONE = () -> "Zone Location";
String getName();
}
例如,我稍后需要在另一堂课中做的是:
switch (locationList) {
case LocationType.MERGE:
break;
case LocationType.MULTI:
break;
}
how can I access these fields from a switch in a different class? I need to do a switch case for each LocationType.
@FunctionalInterface
public interface LocationType {
LocationType UNKNOWN = () -> "Unknown Location";
LocationType MERGE = () -> "Merge Location";
LocationType REGULAR = () -> "Regular Location";
LocationType MULTI = () -> "Multi Location";
LocationType ZONE = () -> "Zone Location";
String getName();
}
e.g. what I need to do later on, in another class is this:
switch (locationList) {
case LocationType.MERGE:
break;
case LocationType.MULTI:
break;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您只想通过字符串比较,而不是在此处的枚举列表中进行比较,则可能是一个可能的解决方案。
Assuming that you want to compare only by the String and not by the number of the enum list here it is a possible solution.