How far to go in replacing inner classes with lambdas?
Joe Bowbeer
joe.bowbeer at gmail.com
Sun Oct 28 10:44:03 PDT 2012
The r -> r.run() refactoring looks OK to me provided it is not transforming
a static nested class into an inner class.
If it is performing this transformation, then I will need to inspect the
use of this lambda and convince myself that it is not retaining or leaking
memory.
We're all aware of the SIC warning from FindBugs:
http://findbugs.sourceforge.net/bugDescriptions.html#SIC_INNER_SHOULD_BE_STATIC
which in my experience is the leading cause of memory leaks.
Joe
On Sun, Oct 28, 2012 at 10:18 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> Brian,
> you can go a step further because either r -> r.run() or Runnable::run are
> non capturing lambdas
> thus they doesn't need to be stored in a static final field.
> So you can replace
>
> public NotificationBroadcasterSupport**(Executor executor,
> MBeanNotificationInfo... info) {
> this.executor = (executor != null) ? executor : defaultExecutor;
> ...
> }
>
> by
>
> public NotificationBroadcasterSupport**(Executor executor,
> MBeanNotificationInfo... info) {
> // if the executor is null, the runnable is executed by the current
> thread
> this.executor = (executor != null) ? executor : r -> r.run();
> ...
> }
>
> You can apply the same idea to j.u.functions.Mappers and Predicates.
>
> cheers,
> Rémi
>
>
More information about the lambda-libs-spec-observers
mailing list