Y
Yamin
Hey all,
This is purely an academic question. I know the easy work around for
it, but I'm just wondering.
I want to know if there's an easy way to explicitly call an outer
classes method from an inner class.
For example
class x
{
public String getName(){ return "xName";}
class y
{
public String getName { return "yName";}
public String getFullName( return x.getName()+ getName;}
}
}
The getFullName should return "xNameyName";
The quesiton is how do your specify x.getName() without getName()
being static.
The easy way to solve this is to simply pass in the outer class as a
parameter to the inner class. Then to call x.getName, you'd simply
use the reference you passed in.
For example
class x
{
public String getName(){ return "xName";}
class y
{
private x myx;
public y(x myx) { this.myx = myx};
public String getName { return "yName";}
public String getFullName( return myx.getName()+ getName;}
}
}
I guess what's I'm asking, is there an equivalent way to address the
outerclass in a similar manner as when you inherit from a baseclass,
you can explicitly call the parent classes member by super.X...is
there something along the lines of an outer.X. I don't think there
is, but just seeing what's out there.
Thanks,
Yamin
This is purely an academic question. I know the easy work around for
it, but I'm just wondering.
I want to know if there's an easy way to explicitly call an outer
classes method from an inner class.
For example
class x
{
public String getName(){ return "xName";}
class y
{
public String getName { return "yName";}
public String getFullName( return x.getName()+ getName;}
}
}
The getFullName should return "xNameyName";
The quesiton is how do your specify x.getName() without getName()
being static.
The easy way to solve this is to simply pass in the outer class as a
parameter to the inner class. Then to call x.getName, you'd simply
use the reference you passed in.
For example
class x
{
public String getName(){ return "xName";}
class y
{
private x myx;
public y(x myx) { this.myx = myx};
public String getName { return "yName";}
public String getFullName( return myx.getName()+ getName;}
}
}
I guess what's I'm asking, is there an equivalent way to address the
outerclass in a similar manner as when you inherit from a baseclass,
you can explicitly call the parent classes member by super.X...is
there something along the lines of an outer.X. I don't think there
is, but just seeing what's out there.
Thanks,
Yamin