Skip to content

Instantly share code, notes, and snippets.

@afinlay5
Created August 22, 2018 05:14
Show Gist options
  • Save afinlay5/38c4b69526dc0fe5d953d417fb2446be to your computer and use it in GitHub Desktop.
Save afinlay5/38c4b69526dc0fe5d953d417fb2446be to your computer and use it in GitHub Desktop.
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