对象A中有点位和点位描述 俩个元素 java代码 将对象A转换成枚举
时间: 2024-04-30 12:24:26 浏览: 71
假设对象A定义如下:
```java
public class A {
private String point;
private String description;
public A(String point, String description) {
this.point = point;
this.description = description;
}
public String getPoint() {
return point;
}
public void setPoint(String point) {
this.point = point;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
```
可以通过以下方式将其转换成枚举:
```java
public enum AEnum {
POINT_A("A", "Point A description"),
POINT_B("B", "Point B description"),
POINT_C("C", "Point C description");
private String point;
private String description;
AEnum(String point, String description) {
this.point = point;
this.description = description;
}
public String getPoint() {
return point;
}
public String getDescription() {
return description;
}
}
```
在枚举类中定义每个点位及其对应的描述,可以通过构造函数传入。然后在枚举类中定义`getPoint()`和`getDescription()`方法,用于获取对应的点位和描述信息。
阅读全文