@JRubyMethod public static IRubyObject to_java( ThreadContext context, IRubyObject fromObject, IRubyObject type) { if (type.isNil()) { return to_java(context, fromObject); } Ruby runtime = context.runtime; JavaClass targetType = getTargetType(context, runtime, type); if (fromObject instanceof RubyArray) { return targetType.javaArrayFromRubyArray(context, fromObject); } else { return Java.getInstance(runtime, fromObject.toJava(targetType.javaClass())); } }