3 ms·
The problem is you don't get compile time checking. If you forget that Foo implements IBar and change the method doSomething() so that it no longer implements I
by MatthewPhillips 15y ago
The problem is you don't get compile time checking. If you forget that Foo implements IBar and change the method doSomething() so that it no longer implements IBar you only find out with runtime bugs.
I really like Go but it's been a while since I used it. Someone correct me if I'm wrong here.
- dchest 15y agopackage main type IBar interface { doSomething() } type Foo int func (f Foo) doSomething() { println(f) } func test(b IBar) { b.doSomething() } func main() { f := Foo(1) test(f) } Compile, run: 1 Rename doSomething function to doSomethingElse. Compile: test.go:20: cannot use f (type Foo) as type IBar in function argument: Foo does not implement IBar (missing doSomething method)
- MatthewPhillips 15y agoUnit testing to the rescue.
- azth 15y agoMore like just compiling =)