Given:
type Inf interface {}
type A struct {v int}
x := A{1}
ix := Inf(x)
I can use a type assertion, to get a copy of x:
y := ix.(A)
But what if I want to recover a pointer to x in order to update it? Am
I missing something or is this not possible?
BTW, I know I can do this
y.v++
ix = y
But if A is large then I might not want to incur the overhead of a
copy-by-value.
Thanks
>
> Is there a way, given a variable of interface type, of getting a
> pointer to the value stored in the variable?
>
> Given:
>
> type Inf interface {}
> type A struct {v int}
>
> x := A{1}
> ix := Inf(x)
>
> I can use a type assertion, to get a copy of x:
>
> y := ix.(A)
>
> But what if I want to recover a pointer to x in order to update it? Am
> I missing something or is this not possible?
It is not possible.
> BTW, I know I can do this
>
> y.v++
> ix = y
>
> But if A is large then I might not want to incur the overhead of a
> copy-by-value.
That's the tradeoff.
-rob
Is there a way, given a variable of interface type, of getting a
pointer to the value stored in the variable?
Given:
type Inf interface {}
type A struct {v int}
x := A{1}
ix := Inf(x)