Comment on C# almost has implicit interfacesComments−WhereIsTheTruth2yYou can in D struct Foo { void read(){} } struct Bar { void read(){} } struct Nope { } void handle(T)(T data) { static if (__traits(hasMember, data, "read") == false) static assert(0, "struct needs a 'read' function"); data.read(); } void main() { Foo foo; Bar bar; Nope nope; handle(foo); // works handle(bar); // works handle(nope); // oops main.d(17): Error: static assert: "struct needs a 'read' function" }
Comments
You can in D