I have a question about return types in legacy methods in Java. I have a class and an inherited class. There is a specific method in the inherited class. It also inherits a parent class method that returns an instance of itself.
I want something like this class hierarchy:
public class Foo { public Foo bar() { return this; } } public class FooInherited extends Foo { public Whatever baz() { return new Whatever(); } }
My question is, can I call the inherited method from its instance, and then call the specific method without overriding the method, in order to return the inherited class or explicitly call the classes.
Now I want to have a piece of code like this:
FooInherited foo = new FooInherited(); Whatever w = foo.bar().baz();
I have difficulty with this, but I'm not very sure that Java has a time-saving mechanism for programmers in such situations.
source share