-
6 votesanswersviews
鸭子在D打字
我是D的新手,我想知道是否可以方便地进行编译时检查的鸭子打字 . 例如,我将'd like to define a set of methods, and require that those methods be defined for the type that'传递给一个函数 . 它与D中的 interface 略有不同,因为我不必在任何地方声明"type X implements... -
1 votesanswersviews
与mypy的可比类型
我正在尝试创建一个泛型类来表示值具有下限和上限,并强制执行这些边界 . from typing import Any, Optional, TypeVar T = TypeVar("T") class Bounded(object): def __init__(self, minValue: T, maxValue: T) -> None: a... -
14 votesanswersviews
为什么TypeScript中的类允许使用duck typing
在TypeScript中看起来绝对没问题(从编译器的角度来看)有这样的代码: class Vehicle { public run(): void { console.log('Vehicle.run'); } } class Task { public run(): void { console.log('Task.run'); } } function runTask(t:...