-1

I have the class X and a variable called x In my inner class Y I have a variable called y

I want: x = y

I made a Getter Method for Y and for X but the error accurs: non-static method 'getY()' cannot be referenced from a static context.

I haven't set the getX() static nor final. I have tried it both ways as well but it's not working.

EDIT:

public class X {
    Variable v = new Variable();
    [... here is something done with v]

    class Y {
      Variable v_new = v;
      [works with v]

    }

    v = v_new; // ???
}
Joe
  • 15
  • 1
  • 6

1 Answers1

1

Your inner class Y can access class X's variable v, so no need to redeclare it as variable v_new...
If you must, then use a public getter method, and reference it through an instance of Y.

Something like this:

public class X {
  Variable v = new Variable();
  [... here is something done with v]

  class Y { 
    Variable v_new = v;
    [works with v]
    public Variable getV() { return v_new; }
  }

  Y y = new Y();
  v = y.getV();
} 
Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
Usagi Miyamoto
  • 6,196
  • 1
  • 19
  • 33