1

如何使用 JavaPoet 生成以下枚举类?

public enum Planet {
    MERCURY (3, 2),
    VENUS   (4, 6)
}
4

1 回答 1

5
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();
于 2016-06-21T10:12:08.823 回答