本文发表在 rolia.net 枫下论坛For some reason, I need to make a little customization on a Java open source API.
There are 2 classes in this API.
public class Grandfather
{
public add( Object a)
{
......
}
}
public class Father extends Grandfather
{
public add( Object a )
{
super.add(a);
specific process in Father.....
}
}
In my case, the "specific process" in class Father doesn't meet my requirement. I need it to have the special behaviors
under some certain condition. However, those conditions cannot be distinguished from inside
this class's perspective or by the parameter passed in. Therefore, adding in a new processing flow wouldn't help solve this problem
Then I tried to create a class named Uncle that extends Grandfather and overrode the method "add" with my customized code.
Unfortunately, there's cast operation somewhere else in this API. So when I ran my program, a ClassCastException
was thrown out.
It means I'd better use the children classes of Father if I don't want to get more complex work.
I guess the easiest way to work this around is to have my class inherited from the class Father and override the
method.
My question is, is that possible to refer to the Grandfather's method "add" from Self? If yes, how?
Thank you.更多精彩文章及讨论,请光临枫下论坛 rolia.net
There are 2 classes in this API.
public class Grandfather
{
public add( Object a)
{
......
}
}
public class Father extends Grandfather
{
public add( Object a )
{
super.add(a);
specific process in Father.....
}
}
In my case, the "specific process" in class Father doesn't meet my requirement. I need it to have the special behaviors
under some certain condition. However, those conditions cannot be distinguished from inside
this class's perspective or by the parameter passed in. Therefore, adding in a new processing flow wouldn't help solve this problem
Then I tried to create a class named Uncle that extends Grandfather and overrode the method "add" with my customized code.
Unfortunately, there's cast operation somewhere else in this API. So when I ran my program, a ClassCastException
was thrown out.
It means I'd better use the children classes of Father if I don't want to get more complex work.
I guess the easiest way to work this around is to have my class inherited from the class Father and override the
method.
My question is, is that possible to refer to the Grandfather's method "add" from Self? If yes, how?
Thank you.更多精彩文章及讨论,请光临枫下论坛 rolia.net