org.jruby.util.collections.ClassValue Maven / Gradle / Ivy
package org.jruby.util.collections;
import org.jruby.util.cli.Options;
/**
* Represents a cache or other mechanism for getting the Ruby-level proxy classes
* for a given Java class.
*/
@SuppressWarnings("unchecked")
public abstract class ClassValue {
public ClassValue(ClassValueCalculator calculator) {
this.calculator = calculator;
}
public abstract T get(Class cls);
protected final ClassValueCalculator calculator;
public static ClassValue newInstance(ClassValueCalculator calculator) {
if ( JAVA7_CLASS_VALUE ) return newJava7Instance(calculator);
return new MapBasedClassValue(calculator);
}
private static ClassValue newJava7Instance(ClassValueCalculator calculator) {
return new Java7ClassValue(calculator);
}
private static final boolean JAVA7_CLASS_VALUE;
static {
boolean java7ClassValue = false;
if ( Options.INVOKEDYNAMIC_CLASS_VALUES.load() ) {
try {
Class.forName("java.lang.ClassValue");
Class.forName("org.jruby.util.collections.Java7ClassValue");
java7ClassValue = true;
}
catch (Exception ex) {
// fall through to Map version
}
}
JAVA7_CLASS_VALUE = java7ClassValue;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy