In that code there's an outer task with a constructor that instantiates a private static member class but only assigns the result to a reference once. I'm not sure what to make of this. Is the static inner class only instantiated the first time? And does each invocation of "new" only intended to complete the building of a concrete class from the abstract static inner class? I assume the single reference is all that's needed to access that inner object. Do the additional uses of the "new" keyword actually return a reference that can be assigned?
Yes, each of the three "new" expressions represents a different anonymous inner class. Notice that although they each extend the same static inner class, each of them extends it in a different way. Hence, three different anonymous inner classes.
And yes, the static inner class is only loaded (not "instantiated") once. When you load a class, the JVM automatically first loads its superclass if it isn't already loaded. So when you load the first of the anonymous inner classes, by instantiating an object of said class, that causes the static inner class to be loaded.
And yes, "new" always produces a reference to an object which can be assigned. Not just in this particular obscure example, but always.
If you carefully look at the definition of ColumnViewerSorter, you see that in its constructor, it adds an event listener to the viewer you pass as a constructor argument; that listener is connected to the ColumnViewerSorter itself. Therefore just constructing one of these also wires it up, and keeps a reference to it. The only reason the first one is assigned to a variable is so that soon after some other methods can be called on it -- i.e.,
One last note: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Initials aren't enough. If "Nj" is not your real last name, you can change your display name here. Thanks!