These methods can’t (re)define type parameter section. The following won’t compile:
which is on my understanding means that once you declare a type parameter of X in the class declaration, declaring a type parameter of X in a method level will result to compile error. But trying those out results to compiling successfully.
Am I assuming wrong in my understanding that I have mentioned or am I missing something?
Can you give a bit more context? Frankly, I don't understand what original code in the book is trying to achieve.
Your code works because:
1) In MyInterface, you are defining a method print - which returns X - and X is generic type (hence <X>). Try <X> print(X t) and it won't work (but again, I'm unable to understand why somebody would do that).
2) In MyClass, you are mentioning that X is generic (i.e. <X>) and method print returns void (thus, <X> is actually redundant).