3 ms·
package main type IBar interface { doSomething() } type Foo int func (f Foo) doSomething() { println(f) } func test(b IBar) { b.doSome
by dchest 15y ago
package 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 =)