Last active
August 29, 2015 13:58
-
-
Save JeffreyZhao/9933999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 引入voidable修饰符,用于修饰泛型参数。 | |
* 被修饰的泛型参数T,可以在代码里具体化为void类型。 | |
*/ | |
class Task<voidable T> { } // 带有voidable修饰 | |
class List<T> { } // 不带voidable修饰 | |
/* | |
* 于是乎 | |
*/ | |
Task<int> intTask; // 正常 | |
Task<void> voidTask; // 正常 | |
typeof(Task<>).MakeGenericType(typeof(int)); // 正常 | |
typeof(Task<>).MakeGenericType(typeof(void)); // 正常 | |
List<int> intList; // 正常 | |
List<void> voidList; // 编译失败 | |
typeof(List<>).MakeGenericType(typeof(int)); // 正常 | |
typeof(List<>).MakeGenericType(typeof(void)); // 抛出NotSupportedException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
还要补充一下voidable T在类型里面使用的编译限制。