An
annotation is metadata. Annotations do not directly affect program
semantics, but they do affect the way programs are treated by tools
and libraries, which can in turn affect the semantics of the running
program. Annotations can be read from source files, class files, or
reflectively at run time.
For
Example
public class SuperClass { public void print(){ } }
import java.lang.annotation.Annotation; public class SubClass extends SuperClass{ @Override public void Print(){ } }
When
you tries to compile the above program below error thrown.
SubClass.java:4: error: method does not override or implement a method from a supertype @Override ^ 1 error
Since
Print method in SubClass.java actually not overriding the method in
SuperClass.java. Becaue the method Print in SubClass.java starts with
Capital 'P' where as SuperClass.java starts with small 'p'.
Now
change the method name in SubClass.java and recompile.
import java.lang.annotation.Annotation; public class SubClass extends SuperClass{ @Override public void print(){ } }
No comments:
Post a Comment