public @ Nullable < Z > Z mapWithCopy ( Function < T , Z > f ) throws IOException { final @ Nullable SharedReference < T > localRef = getCopy ( ) ; try { if ( localRef == null ) { return f . apply ( null ) ; } else { return f . apply ( localRef . get ( ) ) ; } } finally { if ( localRef != null ) localRef . close ( ) ; } }
Call some function f on a threadsafe copy of the reference we are storing . Should be used if you expect the function to take a while to run . Saving the value of T after this call returns is COMPLETELY UNSAFE . Don t do it .