Rewriting the initialization to be more meaningful for clueless reader that does not need to understand every detail
1.1 --- a/samples/friendpackage/src/implpkg/Accessor.java Fri Oct 24 11:32:33 2008 +0200
1.2 +++ b/samples/friendpackage/src/implpkg/Accessor.java Fri Oct 24 12:07:34 2008 +0200
1.3 @@ -25,19 +25,10 @@
1.4 private static volatile Accessor DEFAULT;
1.5 public static Accessor getDefault() {
1.6 Accessor a = DEFAULT;
1.7 - if (a != null) {
1.8 - return a;
1.9 + if (a == null) {
1.10 + throw new IllegalStateException("Something is wrong: " + a);
1.11 }
1.12 -
1.13 - try {
1.14 - Class.forName(
1.15 - Item.class.getName(), true, Item.class.getClassLoader()
1.16 - );
1.17 - } catch (Exception ex) {
1.18 - ex.printStackTrace();
1.19 - }
1.20 -
1.21 - return DEFAULT;
1.22 + return a;
1.23 }
1.24
1.25 public static void setDefault(Accessor accessor) {
1.26 @@ -52,5 +43,18 @@
1.27
1.28 protected abstract Item newItem();
1.29 protected abstract void addChangeListener(Item item, ChangeListener l);
1.30 +// FINISH: design.less.friend.Accessor
1.31 +
1.32 + // BEGIN: design.less.friend.InitAPI
1.33 + private static final Class<?> INIT_API_CLASS = loadClass(Item.class.getName());
1.34 + private static Class<?> loadClass(String name) {
1.35 + try {
1.36 + return Class.forName(
1.37 + name, true, Accessor.class.getClassLoader()
1.38 + );
1.39 + } catch (Exception ex) {
1.40 + throw new RuntimeException(ex);
1.41 + }
1.42 + }
1.43 + // END: design.less.friend.InitAPI
1.44 }
1.45 -// END: design.less.friend.Accessor