< prev index next >
src/java.base/share/classes/jdk/experimental/value/ValueType.java
Print this page
@@ -130,33 +130,35 @@
}
private static final ConcurrentHashMap<Class<?>, ValueType<?>> BOX_TO_VT = new ConcurrentHashMap<>();
public static boolean classHasValueType(Class<?> x) {
- return MinimalValueTypes_1_0.classHasValueType(x);
+ if (!MinimalValueTypes_1_0.isValueCapable(x)) {
+ return false;
+ }
+ return MinimalValueTypes_1_0.getValueTypeClass(x) != null;
}
@SuppressWarnings("unchecked")
public static <T> ValueType<T> forClass(Class<T> x) {
+ if (!MinimalValueTypes_1_0.isValueCapable(x)) {
+ throw new IllegalArgumentException("Class " + x + " not a value capable class");
+ }
+
ValueType<T> vt = (ValueType<T>) BOX_TO_VT.get(x);
if (vt != null) {
return vt;
}
- try {
Class<T> valueClass = (Class<T>) MinimalValueTypes_1_0.getValueTypeClass(x);
vt = new ValueType<T>(x, valueClass);
ValueType<T> old = (ValueType<T>) BOX_TO_VT.putIfAbsent(x, vt);
if (old != null) {
vt = old;
}
return vt;
}
- catch (ClassNotFoundException cne) {
- throw new IllegalArgumentException("Class " + x + " not bound to ValueType", cne);
- }
- }
private Lookup boxLookup;
private Lookup valueLookup;
private Map<ValueHandleKind.ValueHandleKey, MethodHandle> handleMap = new ConcurrentHashMap<>();
@@ -181,19 +183,16 @@
public Class<?> arrayValueClass() {
return arrayValueClass(1);
}
public Class<?> arrayValueClass(int dims) {
- try {
String dimsStr = "[[[[[[[[[[[[[[[[";
if (dims < 1 || dims > 16) {
throw new IllegalArgumentException("cannot create array class for dimension > 16");
}
- return Class.forName(dimsStr.substring(0, dims) + "Q" + valueClass().getName() + ";", false, boxLookup.lookupClass().getClassLoader());
- } catch (ClassNotFoundException ex) {
- throw new IllegalStateException(ex);
- }
+ String cn = dimsStr.substring(0, dims) + "Q" + valueClass().getName() + ";";
+ return MinimalValueTypes_1_0.loadValueTypeClass(boxLookup.lookupClass(), cn);
}
public String toString() {
return "ValueType boxClass=" + boxClass() + " valueClass=" + valueClass();
}
< prev index next >