MyMarker.java Source code

Java tutorial

Introduction

Here is the source code for MyMarker.java

Source

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;

@Retention(RetentionPolicy.RUNTIME)
@interface MyMarker {
}

public class Main {
    @MyMarker
    public static void myMethod() throws Exception {
        Main ob = new Main();
        Method m = ob.getClass().getMethod("myMethod");
        if (m.isAnnotationPresent(MyMarker.class)) {
            System.out.println("MyMarker is present.");
        }
    }

    public static void main(String args[]) throws Exception {
        myMethod();
    }
}