Your interface has a generic ToEntity<T> method that you added to your Gens implementation class as a generic Gens class, like ToEntity<MyOtherClass> . (The generic method can accept any type parameter, possibly with certain restrictions on T Your Gens class tries to provide a definition for ToEntity only for a parameter of type MyOtherClass , which defeats the generics target.)
In your code example, it is not clear how your Gens class is trying to use the MyOtherClass type; he, of course, is not involved in ToEntity logic. We need additional information to be able to take you further.
To illustrate here what your current ITranslator<E, R> interface definition offers in plain English:
"I provide a mechanism for translating any record of type R into an object of type E , this mechanism is dependent on any user type T "
Your Gens class, on the other hand, the way it is being developed, "implements" the above interface as follows:
"I can translate integers into strings. I give the illusion of allowing the user to specify the type of control how this translation is performed, but there really is no choice. The MyOtherClass class is MyOtherClass involved; that is all I can say."
It can be seen from these two descriptions that the Gens class does not fulfill what the ITranslator<E, R> interface guarantees . Namely, he does not want to accept the type specified by the user for his ToEntity method. That is why this code will not compile for you.
Dan tao
source share