Standard library / go/types
go/types.Comparable()
Reports whether values of the given type can be compared for equality. Interface comparisons may still panic at runtime. Expected stdout: 'true false\n'.
Formal Syntax & Structure
go syntaxgo
func Comparable(T Type) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| T | Type | Destination type or interface, or type to inspect. |
Return Value
bool
Reports whether values of the given type can be compared for equality.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { fmt.Println(types.Comparable(types.Typ[types.Int]), types.Comparable(types.NewSlice(types.Typ[types.Int])))}