Jimmy Schementi wrote:
How about adding NilClass#as(class)? This is much less likely to cause
name collisions. We have the same issue with IronRuby, and this is the
solution we are favoring currently.
obj.doSomething(nil.as <http://nil.as>(Component), 0)
~Jimmy
I'm still trying to think about how to implement casting in a good way.
The interesting aspect of casting is that it should only be used when
calling into Java methods. In my mind that means a cast should be nop if
done anywhere else. It also shouldn't add methods to objects, so I'm
strongly against adding an "as" method. Especially since such a method
could conceivably have a good use in Ruby code.
It's much better to turn it around and let the Java class have the cast
method, since then it only affects the Java classes.
So say we have Component.cast(nil). What should it return? A Java proxy
of some kind that looks like the original object but have a cast-flag.
That seems expensive.
I would be much more inclined to add syntax specifically for this -
except we generally don't like adding syntax at all.
Cheers
On Thu, Aug 6, 2009 at 9:33 AM, Martin McNulty
<[email protected] <mailto:[email protected]>> wrote:
HashMap.null
Doesn't use 'nil', but then I guess it is a Java
null you're passing into the method... Handily can't conflict with a
Java field name.
I have almost no idea of how this would be implemented though, so
perhaps this suggestion's a really bad one ;)
Martin
2009/8/6 Thomas E Enebo <[email protected]
<mailto:[email protected]>>:
> nil.to_java(HashMap)
>
> -Tom
>
> On Thu, Aug 6, 2009 at 1:50 AM, Charles Oliver
> Nutter<[email protected] <mailto:[email protected]>> wrote:
>> This is an important one:
>>
>> http://jira.codehaus.org/browse/JRUBY-3865
>>
>> It's definitely not a hypothetical situation, and I have had
this come
>> up a few times myself. Perhaps we can have some discussion here
or on
>> the bug about what our casting syntax should look like?
>>
>> - Charlie
--
Ola Bini (http://olabini.com)
Ioke creator (http://ioke.org)
JRuby Core Developer (http://jruby.org)
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)
"Yields falsehood when quined" yields falsehood when quined.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email