I have a class that I don't have access to its source.
public class IDontHaveAccessToSource {...}
I'd like to add some methods to it, like so:
public class MyClass extends IDontHaveAccessToSource {
myMethod1() {...}
myMethod2() {...}
@Override
methodInIDontHaveAccessToSource(){...}
}
but it will give me a ClassCastException
whenever I want to cast anything that returns IDontHaveAccessToSource
to MyClass
.
How can I do such things?
I don't want to use
public class MyClass {
IDontHaveAccessToSource obj;
MyClass(IDontHaveAccessToSource obj) {
this.obj = obj;
}
...
}
And there isn't any constructor available for IDontHaveAccessToSource
. It 'gets created' by calling a function from another class:
IDontHaveAccessToSource obj = loadObject(filename);