Created
April 7, 2016 07:07
-
-
Save jclosure/adeed062033e1a7151876f3aa4d8d4ad to your computer and use it in GitHub Desktop.
Java Annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
annotations could be fine for your purpose. | |
@FileProperties(desc="data file") | |
public class DataFile extends XFile { ... } | |
FileProperties props = DataFile.class.getAnnotation(FileProperties.class); | |
String desc = props.desc(); | |
Accessing the info still requires reflection, however it's a little better than using static field/method. | |
Java compiler does not enforce that all subclasses are annotated as such. You can add your logic to the compiler (using annotation processing) but that's too complicated. It's ok to check it at runtime. | |
Update: | |
This is also possible: | |
@FileInfoClass ( DataFileInfo.class ) | |
@public class DataFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment