|
|
|
|
|
by Doxin
1454 days ago
|
|
The compiler can still do type checking even when using duck typing. It's important to note that duck typing and weak typing are entirely orthogonal. You can have either, both, or neither. E.g. an example in D of a function that doesn't care too much about the type you pass in: T doublify(T)(T v){
return v*2;
}
These are all fine: writeln(doublify(3));
writeln(doublify(3.0));
writeln(doublify(3u));
But this still throws a compile error like you'd expect: writeln(doublify("3"));
|
|