AttributeKey extends UniqueName { @SuppressWarnings("unchecked") public static <T> AttributeKey<T> newInstance(String name) { checkNotNull(name, "name"); AttributeKey<T> option = new AttributeKey<T>(name); AttributeKey<T> old = names.putIfAbsent(name, option); if (old != null) { throw new IllegalArgumentException(String.format("'%s' is already in use", name)); } return option; } @Deprecated  AttributeKey(String name); @SuppressWarnings("unchecked") static AttributeKey<T> valueOf(String name); static boolean exists(String name); @SuppressWarnings("unchecked") static AttributeKey<T> newInstance(String name);  }
@Test public void testNewInstance() { String name = "test2"; assertFalse(AttributeKey.exists(name)); AttributeKey<String> attr = AttributeKey.newInstance(name); assertTrue(AttributeKey.exists(name)); assertNotNull(attr); try { AttributeKey.<String>newInstance(name); fail(); } catch (IllegalArgumentException e) { } }