Suppose I have a class Thing
and some function/method that accepts a thing myFunction(Thing x)
. I want to create a class Thing2
which can be passed into myFunction
, and which replicates the interface of Thing
by supporting all the same public methods and fields etc. One way to do this would be to have Thing2
be a subclass of Thing
. But is there a way to have Thing2
be a subtype of Thing
without making it a subclass — for example, if I don't want Thing2
to inherit private fields of Thing
?
And if it is not possible using regular Java, is it possible to do so by generating Java bytecode via some other means?
I am asking this question purely out of curiosity, I don't actually have a specific problem that I am trying to solve.