Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active May 29, 2025 14:29
Show Gist options
  • Save Integralist/dba19204e096bf43d0e6274d118d8da3 to your computer and use it in GitHub Desktop.
Save Integralist/dba19204e096bf43d0e6274d118d8da3 to your computer and use it in GitHub Desktop.
Go: type cast #go
// https://play.golang.com/p/fLovZCiAzn1
package main
import (
"fmt"
)
type myString string
func main() {
var s myString = "this is my string"
p := &s
fmt.Printf("%#v (%T)\n", p, p) // (*main.myString)(0xc000104020) (*main.myString)
c := (*string)(p)
fmt.Printf("%#v (%T) %#v\n", c, c, *c) // (*string)(0xc000104020) (*string) "this is my string"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment