Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Last active July 5, 2018 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-neck/3f5b1b31fc10f6143f18fafdbb297774 to your computer and use it in GitHub Desktop.
Save mike-neck/3f5b1b31fc10f6143f18fafdbb297774 to your computer and use it in GitHub Desktop.
アノテーションの equals とかどうなんだっけと思って調べた
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