Workaround for assignment in Java?

After reading this thread , I understand that it cannot be assigned thisin Java. But are there any workarounds? I have the following situation. I am writing a subclass B, but the base class Adoes not have explicit constructors or methods that would allow me to create an object based on my arguments. The only available way is to call an external function F():

public class B extends A {   
   public B(some args) {     
       A a = F(some args);
       this = a;
   }
}

Both Aand F()are external libraries A- a fairly complex object and F()implements a sophisticated algorithm.

The only solution I can think of is to simply not subclass:

public class B {
   public A a;   
   public B(some args) {     
       a = F(some args);      
   }
}

It does not look very attractive. What would be the least ugly solution in this situation?

+4
1

. , . A , B A, , .

, B A. , . , class A, , interface IA. A class B implements IA. - A B, .

( , , .)


, Java IDE , , , Java IDE Java. , Java . IDE private member A, , " ..." - . - " ...". , A B, . IDE B, .

int method() {
    return a.method();
}

" " .

+4

All Articles