@ SuppressWarnings ( "unchecked" ) public T swap ( T value ) { final Holder holder ; final T oldValue ; WeakReference < Holder > ref = local . get ( ) ; if ( ref != null ) { holder = ref . get ( ) ; Object holderValue = holder . value ; if ( holderValue != UNINITIALISED ) { oldValue = ( T ) holderValue ; } else { oldValue = initialValue ( ) ; } } else { holder = createHolder ( ) ; oldValue = initialValue ( ) ; } holder . value = value ; return oldValue ; }
Swaps the current threads value with the supplied value . Thread - local will be initialised if not already done so .