Generics and static members

  • Thread starter Thread starter Filip Zawada
  • Start date Start date
F

Filip Zawada

Hi,

I've encountered a rather interesting language problem. Suppose I've
got following types:

//class providing usefull static methods
public class GoodBase<T>
{
public static void Met(){};
}

public class SomeEntity
: GoodBase<SomeEntity>
{
}

public interface IDictModel<T>
where T : GoodBase<T>
{
}

public class DictModel<T>
: IDictModel<T>
where T : GoodBase<T>
{
public void Test()
{
GoodBase<SomeEntity>.Met(); //OK
SomeEntity.Met(); //OK
T.Met(); //won't compile
}
}

The question is why can't I call a static method using generic
parameter?

I've specified that T is of type GoodBase<T>, so static methods from
GoodBase should be available by using generic parameter... Isn't
GoodBase<SomeEntity>.Met() actually the same as T.Met()? Why do I have
to repeat myself?

Regards,
Filip Zawada
 
Thank you for the answer, Pete. It was very helpful.
Now as I know the reasons, it's so obvious.

Filip
 
Back
Top