I guess your example was written to be compact for the sake of the hurrying
an answer to the OP, but I think that cascading method calls like your code
does is not a good idea.
I have long advocated that programmers should not manually format
programs, the IDE/SCID should do it automatically. see
http://mindprod.com/projects/scid.html Further, every viewer should
have the right to view code in his or her preferred style, even in a
team programming situation.
I have been using Eclipse. I now pay absolutely no heed to formatting
any more, even though Eclipse is still only about 90% of the way there
in terms of what I would like in formatting. Eclipse aggressively
cleans up my code a few minutes later. Unfortunately, that habit of
trusting Eclipse to tidy up has obviously spilled over onto examples
for the newsgroup. I will have to experiment to find some way of
preparing snippets in Eclipse for posting.
About the other issue of splitting out separate temporary variables
for every method call, I disagree, in this particular example, though
I would agree in many other situations.
What I REALLY wanted to say was:
yourTable.addListSelectionListener(new
ListSelectionListener() { anonymous class goes here } );
But Sun does not let me. Presumably to handle complicated cases, they
expose the inner structure of the JTable rather than presenting an
unified facade.
I suggest coding it this way:
yourTable.getSelectionModel().addListSelectionListener
(new ListSelectionListener()
{ anonymous class goes here } );
My code is implying -- that I am just adding a Listener to yourTable.
This gobbledegook about the getSelectetionModel is just what is
required.
If I spell it out as you requested:
ListSelectionModel lm = yourTable.getSelectionModel();
lm.addListSelectionListener(new
ListSelectionListener() { anonymous class goes here } );
There is an implication in the code that the ListSelectionModel has
some importance in its own right. I might reference it again later on
in the code. I might add listeners to some other ListSelectionModel.
I might even change lm's value. It opens up a tiny can of worms that
my version of the code keeps closed. The whole trick of maintainable
code is cutting down on what you have to check.
My version of the code implies that the ListSelectionModel is of no
significance and is used nowhere else in the program.
Perhaps you don't read the code that way, but when I write code for
myself, that is the implication.