c# - Fun with generics: no implicit reference conversion error -
I tested this code and found that it is not compiled.
Interface IE Even if I public static zero F & lt; TU & gt; () Where TU: A & lt; Int & gt;, IE & lt; T & gt;
afaik is valid according to C # specs, if I where TU: IE & lt; T & gt; , but in this situation it can not be affected, because A Sub-type is IE < T & gt; .
And this is also strange because the Rechargeer IE & lt; T & gt; Interface to A
Why is this code not valid?
No, it not is valid
< Code> where TU: IE & lt; T & gt;
current T , that is the way you are calling this method.
Call:
A & lt; String & gt; Fu (); For this TU as a type of argument, a & lt; Int & gt; is trying to pass, but the constraint means that there should be a reference TU to IE , because T is string .
A & lt; Int & gt; to IE , so it is broken. Basically you are expecting " A IE
You can now convert it to:
public static zero F & TTU, TT> () where TU: IE & lt; TT & gt; {} static zero Foo () {F> int>, int> ();}
He is now valid because it does not include T at all.
Comments
Post a Comment