-
1. Re: setSuperClass question
chiba Jun 30, 2003 9:35 AM (in response to huiben)The reason why I don't add a method for doing that
is that it lets the users wrongly change the super
class to break the consistency. Why do you want
to do that? I would like to know if there is a real
example. (If yes, I want to add a method for doing
that.) -
2. Re: setSuperClass question
huiben Jul 8, 2003 9:55 AM (in response to huiben)consider the following 4 classes:
public class A
{
// root class
// some methods
}
public class B
{
public static void method(A obj)
{
// do something with object of class A
}
}
public class C extends A
{
public void method2()
{
B.method(this); // param is super class A
}
}
public class D extends A
{
}
my situation is to make C extends D instead of A, i.e.
public class C extends D
{
// and D extends A, so C also extends A
}
since D also extends A, so C is still a subclass of A, just that D is inserted in between. using Javassist setSuperClass method, this will break the invocation of B.method, because B.method parameter signature is class A, but setSuperClass change it to class D. as a result, I got method not found exception. i.e. it tries to look for B.method(D) instead of B.method(A).
I think setSuperClass blindly replace all occurance of A with D is the root of this problem. It does not consider that there are external dependency with A (in my case, B.method() is depend on A, not D)
that's why I need a different way to setSuperClass.
what do you think chiba?
thanks
ben -
3. Re: setSuperClass question
chiba Jul 9, 2003 3:02 AM (in response to huiben)OK, I understand this issue. Give me time.
-
4. Re: setSuperClass question
chiba Aug 23, 2003 1:40 AM (in response to huiben)Sorry for my too long silence.
I think Ben is right so I made a decision to change
the semantics of setSuperclass() so that
setSuperclass() only changes the extend clause
and constructors.
Note: constructors may call the super's constructor.
If the super class is changed, the constructor body
must be instrumented.