3 ms·
It's much easier to keep track of what's happening if you don't try to write it as one-liners. This: final Runnable newRef = new Counter()::show; is the
by pdpi 10y ago
It's much easier to keep track of what's happening if you don't try to write it as one-liners.
This:
final Runnable newRef = new Counter()::show;
is the same as this:
final Counter counter = new Counter();
final Runnable newRef = counter::show;
Which is roughly equivalent to this:
final Counter counter = new Counter();
final Runnable newRef = () -> { counter.show(); };
Which is, of course, not the same thing as
final Runnable newLambda = () -> { new Counter().show(); };
The rest of the differences follow naturally from this distinction.
- deleted 10y ago[deleted]
- mobiuscog 10y agoAbsolutely this. It took me quite a few reads of the article to work out exactly what the issue was, as the output was what I would have expected intuitively.