Al Hobbs wrote:That's right. You can't put random bits of code in a class. It has to be in something.
The anonymous class gets its rules from the regular class for the most part.
Al Hobbs wrote:They don't consider it to be a statement.
Technically, you might call it a member variable declaration.
The anonymous class expression consists of the following:
- The new operator
- The name of an interface to implement or a class to extend. In this example, the anonymous class is implementing the interface HelloWorld.
- Parentheses that contain the arguments to a constructor, just like a normal class instance creation expression. Note: When you implement an interface, there is no constructor, so you use an empty pair of parentheses, as in this example.
- A body, which is a class declaration body. More specifically, in the body, method declarations are allowed but statements are not.
Stephan van Hulst wrote:
What type would o1.Inner refer to? What type would o2.Inner refer to? Are they different types? If not, why would you have different ways to refer to the same type?
Stephan van Hulst wrote:Another complication. Consider you have a method that accepts an object of type Inner. How would you declare the method parameter if you couldn't write Outer.Inner?
Paul Clapham wrote:In your original example you had an array of int. Here you have an array of Integer.
Matthew Bendford wrote:Varargs T... is not just eyecandy to T[]
That means that a call to a non-private instance method will always call the version provided by the actual runtime type of the object