From: Charles Oliver Nutter Date: 2008-07-22T06:08:10+09:00 Subject: Re: Ruby/Java strings solved the Ruby way Jim Menard wrote: > On Sun, Jul 20, 2008 at 1:36 PM, Charles Oliver Nutter > wrote: > [snip] >> So I propose that instead of always decoding incoming Ruby String into a >> Java String when calling a Java method, we introduce a new type--call it >> JString for now--that represents a Java string. When you require in the Java >> integration support, it would add to Ruby String a method to_jstring (or >> to_String or hey, toString?). So for calls from Ruby to Java, we'd follow >> Ruby coercion protocols and only accept either JString or objects that >> coerce to JString. >> >> Likewise, coming from Java to Ruby, we wouldn't automatically coerce; we'd >> return a JString object that implements to_str. You can then usually pass >> that to String APIs, or just coerce it immediately and go on with your >> business. Since this latter change would break some apps that expect Java >> strings to always be coerced, it would be saved for the next major release >> of JRuby and thoroughly discussed. > > This sounds like an excellent compromise. I vote for to_jstring > because it looks most Ruby-esque. Also up for debate is whether boxed primitives from Java should behave the same way, with a JInteger, JFloat, and so on that can coerce to Fixnum or Float. But boxed primitives are considerably cheaper to coerce than Strings, so it may not be worth it. - Charlie