I’ve written a class that looks like this:
public class MyClass<T>
{
public void doSomething()
{
T.somethingSpecial;
}
}
This code doesn’t compile because the compiler has no idea what T is. I would like to constrain T so that it must inherit a certain class that defines somethingSpecial. Bonus points if you can tell me how to do the same thing by contraining T so that it must implement a certain interface.
It’s called Constraints on Type Parameters.