Skip to content

Instantly share code, notes, and snippets.

@kamatama41
Last active August 29, 2015 14:13
Show Gist options
  • Save kamatama41/f47d4f71069acc5ba300 to your computer and use it in GitHub Desktop.
Save kamatama41/f47d4f71069acc5ba300 to your computer and use it in GitHub Desktop.
Java1.7以上では、abstractメソッドにもアノテーションが適用される ref: http://qiita.com/kamatama_41/items/950ac13f1864530ae3f3
public abstract class Parent {
public abstract Number someMethod();
}
public class Child extends Parent {
@Override
@Sample
public Integer someMethod() {
return 1;
}
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Sample {
}
public class CheckHasSampleAnnotation {
public static void main(String[] args) {
for (Method method : Child.class.getMethods()) {
Sample annotation = method.getAnnotation(Sample.class);
if(annotation != null) {
System.out.println("----- [" + method + "] has @Sample. -----");
} else {
System.out.println("[" + method + "] doesn't have @Sample.");
}
}
}
}
----- [public java.lang.Integer Child.someMethod()] has @Sample. -----
[public java.lang.Number Child.someMethod()] doesn't have @Sample.
[public final void java.lang.Object.wait() throws java.lang.InterruptedException] doesn't have @Sample.
[public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException] doesn't have @Sample.
[public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException] doesn't have @Sample.
[public boolean java.lang.Object.equals(java.lang.Object)] doesn't have @Sample.
[public java.lang.String java.lang.Object.toString()] doesn't have @Sample.
[public native int java.lang.Object.hashCode()] doesn't have @Sample.
[public final native java.lang.Class java.lang.Object.getClass()] doesn't have @Sample.
[public final native void java.lang.Object.notify()] doesn't have @Sample.
[public final native void java.lang.Object.notifyAll()] doesn't have @Sample.
----- [public java.lang.Integer Child.someMethod()] has @Sample. -----
----- [public java.lang.Number Child.someMethod()] has @Sample. -----
[public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException] doesn't have @Sample.
[public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException] doesn't have @Sample.
[public final void java.lang.Object.wait() throws java.lang.InterruptedException] doesn't have @Sample.
[public boolean java.lang.Object.equals(java.lang.Object)] doesn't have @Sample.
[public java.lang.String java.lang.Object.toString()] doesn't have @Sample.
[public native int java.lang.Object.hashCode()] doesn't have @Sample.
[public final native java.lang.Class java.lang.Object.getClass()] doesn't have @Sample.
[public final native void java.lang.Object.notify()] doesn't have @Sample.
[public final native void java.lang.Object.notifyAll()] doesn't have @Sample.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment