Assuming that you want such invocation of that method to work:
UIObjectSub obj = goTo(new UIObjectSub());
You have to make that method generic:
public <T extends UIObject> T goTo(T object) {
//some fancy code here
return object;
}
Now if you invoke that method passing an object of some subclass, the type parameter T
will be inferred as that subclass type.