Is there any Java annotation that sets a field value to it's name, for example:
public interface Protocol {
@Whatever String START; // Here @Whatever annotation would set START to "START" in any static string field.
}
No, But you can use enum class.
public enum Protocol {
START,
END
}
And then when you will write:
System.out.println(Protocol.START);
You will get "START"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.