10

So given the following java class:

class Outer
{
  private int x;
  public Outer(int x) { this.x = x; }
  public class Inner
  {
    private int y;
    public Inner(int y) { this.y = y; }
    public int sum() { return x + y; }
  }
}

I can create an instance of the inner class from Java in the following manner:

Outer o = new Outer(1);
Outer.Inner i = o.new Inner(2);

However, I can't seem how to do the same from JRuby

#!/usr/bin/env jruby
require 'java'
java_import 'Outer'

o = Outer.new(1);
i = o.Inner.new(2); #=> NoMethodError: undefined method `Inner' for #<Outer...>

What's the correct way to do this?

rampion
  • 87,131
  • 49
  • 199
  • 315

2 Answers2

9
i = Outer::Inner.new(o,2)
sepp2k
  • 363,768
  • 54
  • 674
  • 675
2

From what can be seen in this discussion, you'll have to do Outer:Inner.new(o, 2)

Valentin Rocher
  • 11,667
  • 45
  • 59