call super method outside of 'this'
Hi,
i would like to call a method defined in an ancestor class from a descendant class but outside of the scope of 'this'. The code below shows clearly what i need. The line with "INVALID!" remark shows the prolematic point. Is that call possible in any way?
Thanks.
Code Java:
public class Base {
private String name;
public String getName() {
return name; // it is for example only, it is very complex in real app
}
}
Code Java:
public class Sub extends Base {
private Sub previous; // implements an one way list
@Override
public String getName() {
Sub sub = this;
while (sub.previous!=null) sub = sub.previous; // name is stored only in the first object
return sub.super.getName(); // INVALID!
}
}
Re: call super method outside of 'this'
Why not return super.getName()? In this context there is no need for 'this'. If however, you want a reference to an object in another client and call the parent function rather than the inherited implementation, as far as I know you cannot...and I'd recommend re-evaluating the design should you find the need to do so.