Hi, cowboys!
Many thanks to wise owen for his
link!!!
I think it is NOT possible to understand the output of the code (see start of this
thread)
UNLESS
you know what this
synthetic bridge is.
Tom's first sentence
The point here is not about covariant returns - (...)
can be a bit misleading, as it refers to his example, not to the original problem.
Correct me if I'm wrong:
The problem of the code (at the beginning of the thread) has nothing to do with the different behaviour of variables and non-static methods regarding
polymorphism in the first place.
It is all about this synthetic bridge thing and covariant returns.
And in the original example, a B will be returned, not an A.
To
test this, I put a bug into the code.
Therefor the code below will NOT compile. Due to this synthetic bridge thing, calling getObject() polymorphically, an A and NOT a B will be returned.
Without the problem line, it will output:
Covariance Demo
Child
gimme an A!
Yours,
Bu.
slightly adapted: