It was difficult to search for information on this because I don’t know what it’s called, so that’s my first question I guess.
Does the use of this notation:
new Object() {//code here}
create a new object of type Object or create a new object that is a subclass of object? If it is a subclass, can you put everything you could use to declare a class (member variables, functions, inner classes), inside the braces? Could you even write a constructor for it?
This is called an anonymous class. Basically, you’re defining a subclass in-place.
This call:
.. defines a new subclass of Object with
//stuffin it (just like declaring that in a normalA extends Object.Wikipedia has a good article about them too.
They’re useful primarily for closures, which means that the functions defined in your anonymous class have access to
finalvariables from the enclosing scope.Example-ish: