Created
August 22, 2018 05:14
-
-
Save afinlay5/38c4b69526dc0fe5d953d417fb2446be to your computer and use it in GitHub Desktop.
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 VarAnonInner { | |
public static void main (String[] args) throws Exception { | |
var anonInner = new Anon() { | |
public void hello() { | |
System.out.println("New method here, and you can easily access me in Java 10!\n" + | |
"The class is: " + this.getClass() | |
); | |
}; | |
}; | |
anonInner.hello(); | |
Anon anonInner2 = new Anon() { | |
public void hello() { System.out.println("Woah! "); }; | |
}; | |
anonInner2.getClass().getMethod("hello").invoke(anonInner2); | |
new Anon() { public void hello() { System.out.println("Woah!!! "); }; }.hello(); | |
// VarAnonInner$1 vw = anonInner; | |
/* | |
Anon anonInner4 = new Anon() { | |
public void hello() { | |
System.out.println("New method here!\n" + | |
"The class is: " + this.getClass() | |
); | |
}; | |
}; | |
anonInner4.hello(); | |
*/ | |
} | |
} | |
class Anon { }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment