Interfaces
This is a long section...
Example
package main
import (
"fmt"
"math"
)
func main() {
var a Abser
f := MyFloat(-math.Sqrt2)
v := Vertex{3, 4}
a = f // a MyFloat implements Abser
fmt.Println(a.Abs())
a = &v // a *Vertex implements Abser
fmt.Println(a.Abs())
}
type MyFloat float64
func (f MyFloat) Abs() float64 {
if f < 0 {
return float64(-f)
}
return float64(f)
}
type Vertex struct {
X, Y float64
}Implicit Implementation
Example
Interface Values
Example
Nil Underlying Values
Nil Interface Values
Empty Interface
Example
Type Assertions
Example
Type Switches
Example
Last updated