using System;
public class Program
{
public static void Main()
{
T<A> g = new T<A>();
T2 g = new T2();
}
}
public class T<A>
{
public static extern implicit operator T<A> (A v);
}
public class T2
{
public static extern implicit operator T2 (A v);
}
public interface A{}
The code only works with T of A. With T2 it gives the error "Compilation error (line 19, col 26): T2.implicit operator T2(A)
: user-defined conversions to or from an interface are not allowed", why is it allowed with generics? Are there any limitations to using generics as a workaround?
This question is not a duplicate of this question because this question is asking why it is allowed with generics and if there are any limitations to this workaround not why user-defined conversions to and from interfaces are not allowed.