@Interface is similar to Interface just it is used as templates for documentation, as a standard; especially useful for team development. However, it's pain on the butt - making the coding so difficult to read.
Example 1:
@interface - declaration
package com.myannotation.examples; /** * Marker annotation to indicate that a method or class * is still in progress. */ public @interface InProgress { }
@interface - using
@com.myannotation.examples.InProgress public void calculateInterest(float amount, float rate) { // Need to finish this method later }
@interface - add a member
package com.myannotation.examples; /** * Annotation type to indicate a task still needs to be * completed. */ public @interface TODO { String value(); }
@interface - using with a member
@com.myannotation.examples.InProgress
@TODO("Need to figure out my debt")
public void calculateMyDebt(float amount, float rate) {
// Need to finish this method later
}
or
@com.myannotation.examples.InProgress
@TODO(value="Need to figure out my debt")
public void calculateMyDebt(float amount, float rate) {
// Need to finish this method later
}
Example 2: A little bit complicate case
package com.myannotation.examples;
public @interface GroupTODO {
public enum Severity { CRITICAL, IMPORTANT, TRIVIAL, DOCUMENTATION };
Severity severity() default Severity.IMPORTANT;
String item();
String assignedTo();
String dateAssigned();
}
@com.myannotation.examples.InProgress
@GroupTODO(
item="Need to figure out my debt",
assignedTo="chefZ",
dateAssigned="08/04/2007"
)
public void calculateMyDebt(float amount, float rate) { // Need to finish this method later }
@com.myannotation.examples.InProgress @GroupTODO( severity=GroupTODO.Severity.DOCUMENTATION, item="Need to explain why I have to pay", assignedTo="chefZ", dateAssigned="08/04/2008" )public void reallyConfusedPayment(int codePoint) { // Really weird payment }If someone expect me to enjoy coding this, he must have some nerds. :-) However, more to come.