Casting null

Hi,

I was looking for a way to cast null to a class, is that possible? I
didn’t
find any info related to this.

Thanks

Could you elaborate on what exactly are you trying to do? Due to duck
typing in Ruby, there is no such thing as “cast to a class” in general.

Regards,
Chiaming H.


From: Fabio Y. [email protected]
To: [email protected]
Sent: Sun, December 13, 2009 11:01:45 AM
Subject: [jruby-user] Casting null

Hi,

I was looking for a way to cast null to a class, is that possible? I
didn’t find any info related to this.

Thanks

In java you can have methods with different signatures based on types,
so
supposing this method interface:

doSomething(String);
doSomething(MyClass class);

And It’s allowed to pass as null, so:

doSomething(null);

However, in Java this cant be compiled, because both methods is
possible,
so:

doSomething((MyClass)null)

To explicit what method I’m wanting to call…

However, I didnt find a way to do this in JRuby.

In Aug 2009 there is some issue track on JIRA, but I dont know if it was
already implemented… at that time the discussion was in design
concerns…

On 13 Dec 2009, at 21:12, Fabio Y. wrote:

doSomething((MyClass)null)

To explicit what method I’m wanting to call…

However, I didnt find a way to do this in JRuby.

One method: [1]

foo.java_send :doSomething , [com.example.MyClass], nil

as the documentation says, if you’re going to repeatedly call a method
this way store the method for later invocation.

Damian

[1]
http://kenai.com/projects/jruby/pages/CallingJavaFromJRuby#Calling_masked_or_unreachable_Java_methods_with_java_send


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email