Hi guys, tried to look everywhere and cannot find an answer.So literally I have this:```var result interface{} = &MyStruct{}...return result.(*MyStruct) // Error: invalid operation: result (variable of type *interface{}) is not an interface```
Is there any way to get the &MyStruct as a result?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/25da3c8f-6126-439a-904a-5fec59cb09f4n%40googlegroups.com.
Ok, looks like it doesn't work.I have got the following error:panic: interface conversion: interface {} is MyStruct, not *MyStructSo the actual code is this: https://go.dev/play/p/jBiPII7rOxGCannot find out what is going on :-(
--On Thursday, 24 November 2022 at 22:29:21 UTC axel.wa...@googlemail.com wrote:Hi,On Thu, Nov 24, 2022 at 11:16 PM Denis P <denis....@gmail.com> wrote:Hi guys, tried to look everywhere and cannot find an answer.So literally I have this:```var result interface{} = &MyStruct{}...return result.(*MyStruct) // Error: invalid operation: result (variable of type *interface{}) is not an interface```No, offense, but you literally do not have that code, because the error message does not fit that code. In your code, `result` has type `interface{}`, whereas in the `return` statement, according to the error message, it has type `*interface{}`. Ergo, you are either shadowing `result` in-between, or the code is not equivalent.In any case, the immediate solution could be to dereference the pointer:return (*result).(*MyStruct)Is there any way to get the &MyStruct as a result?--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/25da3c8f-6126-439a-904a-5fec59cb09f4n%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d1a148b6-99f1-47fa-9c4a-4c8823fb15acn%40googlegroups.com.
Possibly relevant:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/948dc8f3-385e-4f50-a44b-ddf4792e6362n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfE7XX%2BnHJTW36GaoLjQWidY7GCjpHP1zyOJJzMcSq13JA%40mail.gmail.com.