繁体   English   中英

Java注释将字段设置为其名称

[英]Java annotation to set a field to it's name

是否有任何Java注释将字段值设置为其名称,例如:

public interface Protocol {
    @Whatever String START; // Here @Whatever annotation would set START to "START" in any static string field.
}

不,但是您可以使用枚举类。

public enum Protocol  {
   START,
   END
}

然后当你写的时候:

System.out.println(Protocol.START);

您将获得“开始”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM