/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ @Override public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ @Override public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
@Override @SuppressWarnings("unchecked") public <T> T toJava(Class<T> type) { final Object object = getObject(); final Class clazz = object.getClass(); if ( type.isPrimitive() ) { if ( type == Void.TYPE ) return null; if ( object instanceof Number && type != Boolean.TYPE || object instanceof Character && type == Character.TYPE || object instanceof Boolean && type == Boolean.TYPE ) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return (T) object; } } else if ( type.isAssignableFrom(clazz) ) { if ( Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy() ) { getRuntime().getJavaSupport().getObjectProxyCache().put(object, this); } return type.cast(object); } else if ( type.isAssignableFrom(getClass()) ) return type.cast(this); // e.g. IRubyObject.class throw getRuntime().newTypeError("failed to coerce " + clazz.getName() + " to " + type.getName()); } }
@Override @SuppressWarnings("unchecked") public <T> T toJava(Class<T> type) { final Object object = getObject(); final Class clazz = object.getClass(); if ( type.isPrimitive() ) { if ( type == Void.TYPE ) return null; if ( object instanceof Number && type != Boolean.TYPE || object instanceof Character && type == Character.TYPE || object instanceof Boolean && type == Boolean.TYPE ) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return (T) object; } } else if ( type.isAssignableFrom(clazz) ) { if ( Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy() ) { getRuntime().getJavaSupport().getObjectProxyCache().put(object, this); } return type.cast(object); } else if ( type.isAssignableFrom(getClass()) ) return type.cast(this); // e.g. IRubyObject.class throw getRuntime().newTypeError("failed to coerce " + clazz.getName() + " to " + type.getName()); } }
@Override public Object toJava(Class type) { Object obj = getObject(); Class cls = obj.getClass(); if (type.isPrimitive()) { if (type == Void.TYPE) return null; if (obj instanceof Number && type != Boolean.TYPE || obj instanceof Character && type == Character.TYPE || obj instanceof Boolean && type == Boolean.TYPE) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return obj; } } else if (type.isAssignableFrom(cls)) { if (Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy()) { getRuntime().getJavaSupport().getObjectProxyCache().put(obj, this); } return obj; } throw getRuntime().newTypeError("failed to coerce " + cls.getName() + " to " + type.getName()); } }
@Override public Object toJava(Class type) { Object obj = getObject(); Class cls = obj.getClass(); if (type.isPrimitive()) { if (type == Void.TYPE) return null; if (obj instanceof Number && type != Boolean.TYPE || obj instanceof Character && type == Character.TYPE || obj instanceof Boolean && type == Boolean.TYPE) { // FIXME in more permissive call paths, like invokedynamic, this can allow // precision-loading downcasts to happen silently return obj; } } else if (type.isAssignableFrom(cls)) { if (Java.OBJECT_PROXY_CACHE || metaClass.getCacheProxy()) { getRuntime().getJavaSupport().getObjectProxyCache().put(obj, this); } return obj; } throw getRuntime().newTypeError("failed to coerce " + cls.getName() + " to " + type.getName()); } }