5 .net c# clr ironpython dynamic-language-runtime
所以,这种情况是我有一个名为C#泛型类Foo与模板参数T具有的new()约束。我已经声明我的班级是这样的:
class Baz
{
public Baz() { }
}
class Foo<T>
where T : Baz, new()
{
// blah blah
}
Run Code Online (Sandbox Code Playgroud)
在Python中:
class Bar(Baz):
def __init__(self):
""" do various things here """
Run Code Online (Sandbox Code Playgroud)
但是,如果在Python中尝试这样做Foo[Bar],则会收到一条错误消息,告诉我我的Bar类违反了上的约束(即new()约束)Foo<T>。
是什么赋予了?