Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Annotations compilation error. Cannot run the programme

$
0
0
package arrayList;

import java.lang.reflect.*;


@Retention(RetentionPolicy.RUNTIME)
@Interface MyAnnotation{
	String Author();
	String Date();
}


@MyAnnotation(Author = "Dulvin",Date = "06/01/2013")
public class annotations {
	
	@MyAnnotation(Author = "Dulvin", Date = "Today")
	public static void Display(){
		System.out.println("Annotation Starts");
	}
	public static void main(String[] args){
		Display();
		AnnotationCall();
	}
	public static void AnnotationCall(){
		annotations ann = new annotations();
		try{

			Class c = ann.getClass();
			Method m = c.getMethod("Display");
			MyAnnotation a1 = (MyAnnotation)c.getAnnotation(MyAnnotation.class);
			MyAnnotation a2 = (MyAnnotation)m.getAnnotation(MyAnnotation.class);
			System.out.println("Class " + a1.Author());
			System.out.println("class " + a1.Date());
			System.out.println("Method " + a2.Author());
			System.out.println("Method " + a2.Date());
		}
		catch (NoSuchMethodException ex){
			System.out.println("NosuchMethod " + ex.getMessage());
		}
	}
}



"Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at arrayList.annotations.main(annotations.java:20)
" - is the error

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>