Skip to content

Issue with object form constructor by reflection. #2595

@blerins

Description

@blerins

Hello,

According to this documentation: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#constructors
I think this should work:

bruno@dexter:~/workspace/spike/jruby$ jruby --version
jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on OpenJDK 64-Bit Server VM 1.7.0_65-b32 +jit [linux-amd64]
bruno@dexter:~/workspace/spike/jruby$ irb
irb(main):001:0> c = java.awt.Color.java_class.constructor(Java::int, Java::int, Java::int)
=> Java::JavaConstructorint,int,int)>
irb(main):002:0> color = c.new_instance(10,10,10)
=> #<Java::JavaObject:0x3b625be>
irb(main):003:0> color.to_s
=> "java.awt.Color[r=10,g=10,b=10]"
irb(main):004:0> color.red
NoMethodError: undefined method `red' for #<Java::JavaObject:0x3b625be>
    from (irb):4:in `evaluate'
    from org/jruby/RubyKernel.java:1107:in `eval'
    from org/jruby/RubyKernel.java:1507:in `loop'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from /home/bruno/.rbenv/versions/jruby-1.7.19/bin/irb:13:in `(root)'
irb(main):005:0> color.getRed
NoMethodError: undefined method `getRed' for #<Java::JavaObject:0x3b625be>
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1107:in `eval'
    from org/jruby/RubyKernel.java:1507:in `loop'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from org/jruby/RubyKernel.java:1270:in `catch'
    from /home/bruno/.rbenv/versions/jruby-1.7.19/bin/irb:13:in `(root)'

Am I missing something?

Thanks!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions