Last active
July 5, 2018 04:45
-
-
Save mike-neck/3f5b1b31fc10f6143f18fafdbb297774 to your computer and use it in GitHub Desktop.
アノテーションの equals とかどうなんだっけと思って調べた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.annotation.* | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target([ElementType.TYPE, ElementType.METHOD]) | |
@interface Foo { | |
String bar() | |
int baz() | |
} | |
@Foo(bar = 'test', baz = 1) | |
class Qux { | |
@Foo(bar = 'test', baz = 1) | |
def qux() {} | |
} | |
@Foo(bar = 'test', baz = 2) | |
class Waldo { | |
} | |
@Foo(bar = 'test', baz = 1) | |
class Corge { | |
} | |
def foo1 = Qux.getAnnotation(Foo) | |
def foo2 = Waldo.getAnnotation(Foo) | |
def foo3 = Corge.getAnnotation(Foo) | |
def foo1_1 = Qux.getMethod('qux').getAnnotation(Foo) | |
assert foo1 != foo2 | |
assert foo1 == foo3 | |
assert foo1 == foo1_1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment