I have the following situation :
abstract class X { abstract X someMethod (...) {...} }.
Now I want to constrain any implementation of X to have its ‘someMethod’ method return that particular implementation type, not just X :
class X1 extends X { X1 someMethod (...) {...} }.
class X1 extends X { X someMethod (...) {...} }. //want this to be flagged as an error
class X2 extends X { X1 someMethod (...) {...} }. //want this to be flagged as an error too
Is it possible to achieve this using Java generics ?
EDIT
Okay. I only asked the yes/no question and got a “yes”. My fault. What I was actually interested in is “how do I write the declarations”.
This works as well;