I had no idea that the following code was allowed:
1 2 3 4 5 6 7 |
I thought foo() could not be accessed from outside the class, because the class was an anonymous extension of Object. That’s demonstrated here:
1 2 3 4 5 6 7 8 |
Note that Object is the most precise type we can give for o. Somehow there are special rules for accessing an anonymous inner class directly when it is being created.
Did you know this? After working with Java for nearly ten years, I still didn’t.

