Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  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)


Unit testing to the rescue.


More like just compiling =)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: