After reading this thread, I understand that it is not possible to assign to this in Java. But are there any workarounds? I have the following situation. I'm writing a subclass B, but the base class A does not have any explicit constructors or methods that would allow to create the object given my arguments. The only available way is to call some external function F():
public class B extends A {
public B(some args) {
A a = F(some args);
this = a;
}
}
Both A and F() are from external libraries, A is a pretty complex object, and F() implements a sophisticated algorithm.
The only solution I can think of, is simply not to make a subclass:
public class B {
public A a;
public B(some args) {
a = F(some args);
}
}
It doesn't look very appealing though. What would be the least ugly solution in this situation?