views:

113

answers:

2

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?

+3  A: 
i = Outer::Inner.new(o,2)
sepp2k
+2  A: 

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

Valentin Rocher