-
Notifications
You must be signed in to change notification settings - Fork 18k
reflect: reflect.NewAt can't deal with address of interface{} #60804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I find the reason, the number's address is not equal with t's address
So I read the document of reflect, but I don't find any function that can get the pointer of the value that the interface point to. |
No, there's no way to get the "address" of a
You could do
That would provide something you could compare successfully with |
@randall77 https://go.dev/play/p/7MsCSlPDT6s
It is a sensible thing when using json.Unmarshal. https://go.dev/play/p/aLNyxR_tmwf
Although I can make a new pointer by this:
I have to defined a new variable which cost more memory if the struct is so huge. |
This is just a bug in how you're using
It's pretty clear this is not a bug in Go, You might want to ask your question in one of the forums listed here, they will probably be of more help. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When PickData() returns Data type directly , reflect.NewAt works well.
https://go.dev/play/p/b2I5NRsVoTd
When PickData() returns interface{} that contains Data , the program crashes.
https://go.dev/play/p/7MsCSlPDT6s
What did you expect to see?
I want to get a pointer that points to the concrete value of interface{} and then print it.
What did you see instead?
The program crash.
The text was updated successfully, but these errors were encountered: