You only need to check if the value implements the interface if you do not know the type of value. If the type is known, this check is automatically performed by the compiler.
If you really want to check anyways, you can do it with the second method that you specified:
var _ Somether = (*MyType)(nil)
which will be a compile time error:
prog.go:23: cannot use (*MyType)(nil) (type *MyType) as type Somether in assignment: *MyType does not implement Somether (missing Method method) [process exited with non-zero status]
What are you doing here assigns a pointer of type MyType (and nil value) to a variable of type Somether , but since the variable name is _ , it is ignored.
If MyType implemented by Somether , it will compile and do nothing
Dean elbaz
source share