Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.