Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created February 9, 2024 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 #golang
// 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