class CustomClass<T> where T: bool
{
public CustomClass(T defaultValue)
{
init(defaultValue); // why can't the compiler just use void init(bool) here?
}
public void init(bool defaultValue)
{
}
// public void init(int defaultValue) will be implemented later
}
你好。这似乎是一个简单的问题,但我在互联网上找不到答案:为什么编译器不使用 init 方法?我只是想为不同类型提供不同的方法。
相反,它会输出以下错误信息: “'CustomClass.init(bool)' 的最佳重载方法有一些无效的参数”
如果能给一些提示,我将非常感激。
祝好, Chris
public void init(T defaultValue)
? - jcolebrandwhere T: bool
。 - dtbinit(bool)
,而是应该加上判断条件if (T is bool) init(bool)
。 - jcolebrand