使用 JavaPoet 生成枚举
Enum generation using JavaPoet
如何使用 JavaPoet 生成以下枚举 class?
public enum Planet {
MERCURY (3, 2),
VENUS (4, 6)
}
TypeSpec planetTypeSpec =
TypeSpec.enumBuilder("Planet")
.addModifiers(Modifier.PUBLIC)
.addEnumConstant("MERCURY", TypeSpec.anonymousClassBuilder("$L, $L",3,2).build())
.addEnumConstant("VENUS", TypeSpec.anonymousClassBuilder("$L, $L",4,6).build())
.build();
如何使用 JavaPoet 生成以下枚举 class?
public enum Planet {
MERCURY (3, 2),
VENUS (4, 6)
}
TypeSpec planetTypeSpec =
TypeSpec.enumBuilder("Planet")
.addModifiers(Modifier.PUBLIC)
.addEnumConstant("MERCURY", TypeSpec.anonymousClassBuilder("$L, $L",3,2).build())
.addEnumConstant("VENUS", TypeSpec.anonymousClassBuilder("$L, $L",4,6).build())
.build();