Code example for AnnotatedElement

Methods: getAnnotation

0
		try { 
			annotationType = Class.forName(annotationTypeName);
		} catch (Exception ex) {
			throw new IllegalArgumentException(ex);
		} 
		return element.getAnnotation(annotationType
				.asSubclass(Annotation.class));
	} 
 
	// Test program to print named annotation of named class 
	public static void main(String[] args) throws Exception {
		if (args.length != 2) {
			System.out
					.println("Usage: java PrintAnnotation <class> <annotation>");
			System.exit(1);
		} 
		String className = args[0];
		String annotationTypeName = args[1];
		Class<?> klass = Class.forName(className);
		System.out.println(getAnnotation(klass, annotationTypeName));
	}