Generics
Constraint satisfaction and comparability
A type argument usually satisfies a constraint by implementing it. Since Go 1.20, comparable interfaces can satisfy suitable strictly comparable constraints; dynamic values may still cause a comparison panic. Example output: 'true'.
Formal Syntax & Structure
go syntaxgo
func Equal[T comparable](a,b T) boolWorking Example
Example Snippetgo
package main
import "fmt"
func equal[T comparable](a, b T) bool { return a == b }func main() { fmt.Println(equal[any](3, 3))}