Last active
May 5, 2020 10:24
-
-
Save olehcambel/60fedac88a251f88bfcc0f9aae35a8b9 to your computer and use it in GitHub Desktop.
A way to check if struct implements an interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"sort" | |
) | |
type RawMessage []int | |
func (mes RawMessage) Len() int { | |
return len(mes) | |
} | |
var _ sort.Interface = (*RawMessage)(nil) | |
/* | |
^^^^^^^ | |
cannot use (*RawMessage)(nil) (type *RawMessage) as type sort.Interface in assignment: | |
*RawMessage does not implement sort.Interface (missing Less method) | |
*/ | |
func main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment