# HG changeset patch # User Jaroslav Tulach # Date 1224842854 -7200 # Node ID ac16aae50d58c5d29df0b8bf5a509e39d36b24d9 # Parent 321b25b8f6f858b478edfb469003e28d7c3e9311 Rewriting the initialization to be more meaningful for clueless reader that does not need to understand every detail diff -r 321b25b8f6f8 -r ac16aae50d58 samples/friendpackage/src/implpkg/Accessor.java --- a/samples/friendpackage/src/implpkg/Accessor.java Fri Oct 24 11:32:33 2008 +0200 +++ b/samples/friendpackage/src/implpkg/Accessor.java Fri Oct 24 12:07:34 2008 +0200 @@ -25,19 +25,10 @@ private static volatile Accessor DEFAULT; public static Accessor getDefault() { Accessor a = DEFAULT; - if (a != null) { - return a; + if (a == null) { + throw new IllegalStateException("Something is wrong: " + a); } - - try { - Class.forName( - Item.class.getName(), true, Item.class.getClassLoader() - ); - } catch (Exception ex) { - ex.printStackTrace(); - } - - return DEFAULT; + return a; } public static void setDefault(Accessor accessor) { @@ -52,5 +43,18 @@ protected abstract Item newItem(); protected abstract void addChangeListener(Item item, ChangeListener l); +// FINISH: design.less.friend.Accessor + + // BEGIN: design.less.friend.InitAPI + private static final Class INIT_API_CLASS = loadClass(Item.class.getName()); + private static Class loadClass(String name) { + try { + return Class.forName( + name, true, Accessor.class.getClassLoader() + ); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + // END: design.less.friend.InitAPI } -// END: design.less.friend.Accessor