If I have a class as below:
class MyClass<T,U>
{
public void DoSomething(T t)
{
}
public void DoSomething(U u)
{
}
}
But construct it using the same types (new MyClass<int,int>()
)
This compiles fine, but if I try to call DoSomething
it errors because of an ambiguous call, which of course is correct. But what if the method was called through reflection or some other dynamic way. I guess it would throw an exception at run time. So my question is why does the compiler allow me create this class with the same types if there's an exception waiting to happen?