Skip to content

Instantly share code, notes, and snippets.

@dylanz
Created May 19, 2011 16:24
Show Gist options
  • Save dylanz/981165 to your computer and use it in GitHub Desktop.
Save dylanz/981165 to your computer and use it in GitHub Desktop.
Java Annotation Example
/*
* 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