The return value of putIfAbsent
is the existing one if one was already there or null
if there wasn't one and we put the new one in.
f = cache.putIfAbsent(arg, ft);
if (f == null) {
f = ft;
ft.run();
}
So if ( f == null )
means "Did we put ft
in the cache?". Obviously, if we did put it in the cache we now need to set f
to the one in the cache, i.e. ft
.
If we did not put ft
in the cache then f
is already the one in the cache because it is the value returned by putIfAbsent
.