The reflection package provides no way to do this. Even if it were possible
to do with unsafe (not even sure it is, but maybe?), it would be brittle
and tied to an undocumented representation of a function and its captured
variables.

Instead, use a single-method interface. It's easy to create a factory
method that takes a function and adapts it to the interface. And then the
value can be used both to invoke the logic (by calling the one method of
the interface) and for inspecting its concrete type and value.


----
*Josh Humphries*
jh...@bluegosling.com

On Wed, Nov 22, 2017 at 8:26 AM, Hoping White <baihaop...@gmail.com> wrote:

> Hi, all
>
> I known that method of a struct can be a function with explicit receiver,
> like this
>
> type Param struct {
>     v int
> }
>
> func (this *Param) Call() {
>     println(this.v)
> }
>
> p := &Param{v:10}
> t := p.Call
> t()
>
> I wonder how can I get the receiver p from function t through
> reflect. Thanks all.
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to