Last active
May 29, 2025 14:29
-
-
Save Integralist/dba19204e096bf43d0e6274d118d8da3 to your computer and use it in GitHub Desktop.
Go: type cast #go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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