Re: [jruby-user] Re: Differences Between MyClass.class and getClass() in JRuby
Eric West <[email protected]>
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <CANVBD_mtuKFWwcO--Rx_wh-qAYV1+roUpoAq9Gjh6wkpphPiGQ@mail.gmail.com> |
I’m getting the expected result. Using Rsense <http://rsense.github.io/> as an example: require "rsense-core" Java::org.cx4a.rsense.typing::Graph.java_class#=> class org.cx4a.rsense.typing.Graph graph = Java::org.cx4a.rsense.typing::Graph.new#=> #<Java::OrgCx4aRsenseTyping::Graph:0x6d79d6d1> graph.java_class#=> class org.cx4a.rsense.typing.Graph graph.get_class#=> class org.cx4a.rsense.typing.Graph Can you share some example code that produces the result your getting above? Also, I’m running this on JRuby 1.7.12 on Java 7, is it possible you are running an older version of JRuby, or perhaps the development version, JRuby? On Mon, Jul 7, 2014 at 7:26 PM, s shaw <[email protected]> wrote: > (Original message was badly mangled, so resending) > > In Java MyClass.class and (new MyClass()).getClass() return the same > thing. In JRuby the equivalent calls would be Java:: MyClass.java_class > and Java::MyClass.new.get_class right? But these calls return > Java::JavaClass and Java::JavaLang::Class respectively. > > Java::JavaClass seems like a java.lang.Class: it has annotation_present() > and encosing_class() methods. But if you call declared_fields() it returns > an array of Java::JavaField, which does not have java.lang.Field methods > like generic_type(). > > How is one supposed to get a true instance of java.lang.Class , one that > returns java.lang.Field when declared_fields() is called? It appears that > one must first instantiate the given class and then call get_class; of > course this does not work for abstract classes... > >