I learned the other day that you can do this
new Object() {
void hello() {
System.out.println(\"Hello World!\");
}
}.hello();
Adding to Sotirios' answer, here's how to invoke the method through reflection:
Object o = new Object() {
void hello() {
System.out.println("Hello World!");
}
};
Method hello = o.getClass().getDeclaredMethod("hello");
hello.invoke(o);
This allows you to call the method more than once, but other than that, makes little sense.