logo       

Re: [jruby-user] JRuby class arguments: msg#00177

lang.jruby.user

Subject: Re: [jruby-user] JRuby class arguments

On 11/19/07, Patrick Logan <patrickdlogan@xxxxxxxxx> wrote:
> >
> > Perhaps this snippet helps?
> >
> > $ bin/jruby -S irb
> > irb(main):001:0> class Foo
> > irb(main):002:1> include java.lang.Runnable
> > irb(main):003:1> end
> > => Foo
> > irb(main):004:0> Foo.new.java_class
> > => $Proxy7
>
> Thanks. Maybe. I'll look into it when I can get back to my jirb prompt.
>
> That will work for the second argument *if* it implies that when the
> jxpath java code creates a new instance of $Proxy7 then what actually
> happens is a new jruby instance of Foo is created.

Ah, I see. No, the proxy is a java.lang.proxy proxy, and it will not
automatically construct an appropriate backing jruby object if you try
to call newInstance on it.

>
> But what does this say about all jruby objects?
>
> i.e. in jruby, they are all instances of the class Object, but if I do
> the following...
>
> o = Object.new
> j = o.java_class
>
> ...then can I assume that all jruby objects are (in java-land)
> instances of a java class that inherits from "j"?

The #java_class method is only available to objects that either
originate from Java, or are made to implement Java constructs through
mechanisms such as including a Java interface, as I did above with
java.lang.Runnable.

> Or is the java_class $ProxyN class more of an on-demand, dynamically
> generated, bridge to the other world?

Yes.

/Nick

---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise