Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class ?!

 
Hychin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A {
public A (B b) {}
}
class B {
class Inner {
public void function () {
A a = new A(?); // How to create object a
...
}
}
}
 
John Williamer
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is what your after but here goes:
class A {
public A (B b) {}
public A (){}
}

class B {
B h=(B) this;
class Inner {
public void function () {
A a = new A(h); // How to create object a
}
}
}
Hope this helps
 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use B.this directly to access the current instance of the outer class.

Alex
 
Hychin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, alex
A a = new A(B.this); // works well and convenient
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic