Last active
January 19, 2016 13:22
-
-
Save raphw/5fa5a20bb64f383320b2 to your computer and use it in GitHub Desktop.
Receiver type overview
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
public class Foo<T> { | |
class Bar<S> { | |
Bar(Foo<T> Foo.this) {} | |
void bar(Foo<T>.Bar<S> this) {} | |
} | |
static class Qux<S> { | |
void qux(Qux<S> this) {} | |
} | |
void foo(Foo<T> this) {} | |
static void foobar() {} | |
static Class<?> baz() { | |
class Baz<S> { | |
void baz(Baz<S> this) {} | |
} | |
return Baz.class; | |
} | |
public static void main(String[] args) throws Exception { | |
System.out.println(Foo.class.getDeclaredConstructor().getAnnotatedReceiverType().getType()); // class Foo | |
System.out.println(Foo.class.getDeclaredMethod("foo").getAnnotatedReceiverType().getType()); // class Foo | |
System.out.println(Foo.class.getDeclaredMethod("foobar").getAnnotatedReceiverType()); // null | |
System.out.println(Foo.Bar.class.getDeclaredConstructor(Foo.class).getAnnotatedReceiverType().getType()); // class Foo | |
System.out.println(Foo.Bar.class.getDeclaredMethod("bar").getAnnotatedReceiverType().getType()); // class Foo.Bar | |
System.out.println(Foo.Qux.class.getDeclaredConstructor().getAnnotatedReceiverType().getType()); // class Foo | |
System.out.println(Foo.Qux.class.getDeclaredMethod("qux").getAnnotatedReceiverType().getType()); // class Foo.Qux | |
System.out.println(baz().getDeclaredConstructor().getAnnotatedReceiverType().getType()); // class Foo | |
System.out.println(baz().getDeclaredMethod("baz").getAnnotatedReceiverType().getType()); // class Foo.Baz | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment