Skip to content

Instantly share code, notes, and snippets.

@chbaranowski
Created October 24, 2010 09:38
Show Gist options
  • Save chbaranowski/643389 to your computer and use it in GitHub Desktop.
Save chbaranowski/643389 to your computer and use it in GitHub Desktop.
Demo Annotation für SWQS
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// Mit der Annotation kann man definieren ob eine Annotation zur
// Laufzeit ausgewertet werden kann.
@Retention(RetentionPolicy.RUNTIME)
// Mit der Target Annotation kann man eine Annotation markieren
// und damit beschreiben auf welchen Elementen (Class, Method, Field ...) die Annotation genutzt werden
// darf. @TestDescription kann man nur Methoden
// markieren da der ElementType auf ElementType.METHOD gesetzt ist.
@Target(ElementType.METHOD)
// Eine Annotation wird über das Schlüsselwort @interface deklariert in Java.
// Die Deklaration einer Annotation ist ähnlich wie die für Interface.
// Man beschreibt die Operationen mit denen man auf die Attributewerte der
// Annotation zugreift.
public @interface TestDescription {
// Default Attribut wird über die Methode value() definiert.
String value() default "";
// Attribut Titel als String.
String titel() default "";
// Attribut Beschreibung als String.
String description() default "";
// Attribut Priorität int wert von 1 bis 5
// (besser anstelle von int wäre eine ENum Prio).
int prio() default 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment