Re: [jruby-user] Re: Differences Between MyClass.class and getClass() in JRuby
Karol Bucek <[email protected]>
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <CAOcitDKD9MKKHXBvEfdJec9OfEtEQ69Vniz16_SVQTC72mGtpw@mail.gmail.com> |
reflection is a bit "non-trivial" but there's some logic involved (it is mostly due supporting the Ruby side of Java). what you're trying to achieve is "best" done using : * klass.java_class.to_java.getDeclaredFields[0].generic_type* you got the *klass.java_class *right but *declared_fiels* is still a helper from JRuby and returns a *Java::JavaField* p.s. questions such as these might be beneficial for others, maybe next time try asking at http://stackoverflow.com/questions/tagged/jruby On Tue, Jul 8, 2014 at 6:03 AM, s shaw <[email protected]> wrote: > > I’m getting the expected result. > > That's because inspect is calling toString() which outputs "class ...". > If you look at the ruby class you can see the difference: > > ~ >cat /tmp/reflect.rb > klass = java.lang.String > p klass.new.get_class.class > p klass.java_class.class > p klass.new.get_class.declared_fields[0].generic_type > p klass.java_class.declared_fields[0].generic_type > ~ >ruby -v !!:$ > ruby -v /tmp/reflect.rb > jruby 1.7.12 (1.9.3p392) 2014-06-20 643e292 on Java HotSpot(TM) 64-Bit > Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64] > Java::JavaLang::Class > Java::JavaClass > class [C > NoMethodError: undefined method `generic_type' for private final char[] > java.lang.String.value:Java::JavaField > (root) at /tmp/reflect.rb:5 >