Friday, 12 May 2017

Java Tutorial: Annotations in java | Java annotations [Built-In Annotations in Java - @inherited]


Click here to watch in Youtube :
https://www.youtube.com/watch?v=YjjDSBv3h_E&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial: Annotations in java | Java annotations [Built-In Annotations in Java - @inherited] 
InheritedAnnotationDemo.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation
    {

    }

@MyAnnotation
class A
{

}

class B extends A
{

}

public class InheritedAnnotationDemo
{
    public static void main(String[] args)
    {
        System.out.println("Super class Annotation = "+new A().getClass().getAnnotation(
                MyAnnotation.class));
        
        System.out.println("Sub class Annotation = "+new B().getClass().getAnnotation(
                MyAnnotation.class));
    }
}
Output
Super class Annotation = @MyAnnotation()
Sub class Annotation = @MyAnnotation()
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/AnnotationDemo_Inherited_App.rar?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/AnnotationDemo_Inherited_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/47d09ebb24294f7b507419345f38ec4cde27d544/BasicJava/AnnotationDemo_Inherited_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge