...

/

Type Aliasing

Type Aliasing

This lesson takes a look at the concept of aliasing using an example

To define methods on a type you don’t “own”, you need to define an alias​ for the type you want to extend.

Example

Press + to interact
package main
import (
"fmt"
"strings"
)
type MyStr string //using MyStr as an alias for type string
func (s MyStr) Uppercase() string {
return strings.ToUpper(string(s))
}
func main() {
fmt.Println(MyStr("test").Uppercase())
}

Down below is ...

Access this course and 1400+ top-rated courses and projects.