This is a bit of a complex annotation type. It indicates that the annotated class with this type is automatically inherited. More specifically, if you define an annotation with the @Inherited tag, then annotate a class with your annotation, and finally extend the class in a subclass, all properties of the parent class will be inherited into its subclass.
1 2 3 4 5 6 7 8 9 |
package www.technicaljungle.com; import java.lang.annotation.Inherited; @Inherited public @interface InheritedAnnotationInterface { boolean isDone() default true; String getUrl() default "TechnicalJungle.com"; } |
We just need to use custom annotation to be used, instead of full traditional style of “implements interface”.
1 2 3 4 5 6 |
package www.technicaljungle.com; @InheritedAnnotationInterface public class InheritedAnnotationDemo { } |
If annotation is not there then we could have written the boilerplate code with “implements” keyword.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public class InheritedAnnotationDemo implements InheritedAnnotationInterface { public boolean isInherited() { return false; } public String doSomething() { return ""; } public boolean equals(Object obj) { return false; } public int hashCode() { return 0; } public String toString() { return ""; } public Class annotationType() { return null; } } |
Don’t you feel that Annotation based programming is more better to standardize your codebase?
@Annotations