I have 3 classes:
class Superclass
...
public class Generic{
public Generic(Superclass s){...}
}
And a subclass extending Superclass
class SubClass extends Superclass{
public void methodM(){
Generic g = new Generic(???);
...
}
}
In methodM
I use the constructor Generic
and I want to pass a reference to the Superclass instance extended by Subclass. So I don't want to do something like new Generic(new Superclass)
, rather something like: new Generic(super.IdontKnowWhat)
thank you
The reference to the current object is implicitly a reference to a superclass as well (as it extends it).
So you should be able to do
Generic g = new Generic(this);