Created
May 19, 2011 16:24
-
-
Save dylanz/981165 to your computer and use it in GitHub Desktop.
Java Annotation Example
This file contains 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
/* | |
* TortugaTable.java | |
* | |
* This is the Annotation class. | |
* | |
*/ | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface TortugaTable { | |
String tableName(); | |
} | |
/* | |
* User.java | |
* | |
* This is the User model, which uses the TortugaTable annotation. | |
* | |
* As you can see, we can pull out the annotation, and access the annotation declarations. | |
* This is where we can record the datamodel, and pass it over to the web side to change schema. | |
* | |
*/ | |
@TortugaTable(tableName = "users") | |
public class User { | |
public static void main(String[] args) { | |
TortugaTable table = User.class.getAnnotation(TortugaTable.class); | |
System.out.println(table.tableName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment