src/macosx/classes/com/apple/laf/AquaUtils.java

Print this page

        

@@ -175,20 +175,11 @@
         protected abstract T create();
     }
 
     abstract static class RecyclableSingleton<T> {
         final T get() {
-            final AppContext appContext = AppContext.getAppContext();
-            SoftReference<T> ref = (SoftReference<T>) appContext.get(this);
-            if (ref != null) {
-                final T object = ref.get();
-                if (object != null) return object;
-            }
-            final T object = getInstance();
-            ref = new SoftReference<T>(object);
-            appContext.put(this, ref);
-            return object;
+            return AppContext.getSoftReferenceValue(this, () -> getInstance());
         }
 
         void reset() {
             AppContext.getAppContext().remove(this);
         }