Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Generify IRubyObject.toJava to make it more pleasant to use. #5063
This change allow callers to skip the cast when calling toJava
I tested binary compatibility in two ways:
Of course any external JRuby extensions (readline, openssl) will
Bit of a snag...it appears that Class.cast does not work when the desired target is a primitive. This is noted in the toJava for RubyBoolean, since that logic wants to return a boolean but you can't return or cast to boolean from a generified method.
This may not have a generic fix since there does not appear to be any way to programmatically cast primitives.
I have additional fixes and no longer believe the casting issue is a big problem.
After inspecting all our toJava implementations, only a handful can toJava into primitive types. Those cases will be fixed to just do manual casting to the container type.
The generic toJava in JavaProxy could be a problem, but it does not appear to break even when specifying primitive target types for a boxed numeric, probably because it doesn't really coerce to a different type:
This may constitute a bug and get fixed at some point, so I'll make sure the blind casting here is at least smart about primitives.