Your interface has a generic ToEntity<T>
method that you've made non-generic in your implementation class Gens
as ToEntity<MyOtherClass>
. (A generic method could take any type parameter, possibly given certain constraints on T
. Your Gens
class is trying to provide a definition for ToEntity
only for the type parameter MyOtherClass
, which defeats the purpose of generics.)
In your code example, it's unclear how your Gens
class is trying to use the MyOtherClass
type; it's certainly not involved in the logic of ToEntity
. We'd need more information to be able to guide you further.
To illustrate, here's what your current definition of the ITranslator<E, R>
interface offers, in plain English:
"I provide a mechanism to translate
any record of type R
into an entity
of type E
, this mechanism being
dependent upon any user-specified type
T
."
Your Gens
class, on the other hand, the way it's currently designed, "implements" the above interface like so:
"I can translate integers to strings.
I provide the illusion of allowing
the user to specify a type to control
how this translation is performed, but
in fact there is no choice of type.
The MyOtherClass
class is involved
somehow; that's all I can say."
From these two descriptions, it's clear that the Gens
class is not really doing what the ITranslator<E, R>
interface guarantees. Namely, it is not willing to accept a user-specified type for its ToEntity
method. That's why this code won't compile for you.