Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created April 7, 2016 07:07
Show Gist options
  • Save jclosure/adeed062033e1a7151876f3aa4d8d4ad to your computer and use it in GitHub Desktop.
Save jclosure/adeed062033e1a7151876f3aa4d8d4ad to your computer and use it in GitHub Desktop.
Java Annotations
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