Thanks very much Ian - indeed I should have proof read the message. With the last paragraph, I wished to ask for a way to tell a non-nil ` var f Fun` is assigned to `funA` of any instance of structure Alpha, or `funB` of any instance of structure Beta - without performing equality comparison between the instances' method and the `f` variable.
Take an example - suppose there are: - var a1,a2,a3,a4,a5 Alpha - var b1,b2,b3,b4,b5 Beta - var f Fun And that `f` is assigned to any of: - a1.funA, a2.funA ... - b1.funB, b2.funB ... Without performing equality check (f == a1.funA || f == a2.funA || f == a3.funA ...), construct a test condition that evaluates to true only if `f` is assigned to `funA` of any instance of `Alpha`. Kind regards, Howard On Monday, 10 June 2019 07:46:58 UTC+3, Ian Lance Taylor wrote: > > On Sun, Jun 9, 2019 at 9:48 AM Houzuo Guo <[email protected] <javascript:>> > wrote: > > > > Given a function type: type Fun func() > > > > And two structure methods that satisfy the function type: > > > > type Alpha struct { > > } > > func (a Alpha) funA() { > > } > > > > type Beta struct { > > } > > func (b Beta) funB() { > > } > > > > At runtime, is there a way to tell whether a non-nil `var f Fun` is > assigned to an arbitrary instance of structure Alpha, or Beta? Can > reflection help in this case? > > I'm sorry, I don't understand your question. funA and funB are > methods. You can't assign to a method. And the structs have no > fields, so you can't assign to that either. So I'm not sure what you > mean. > > That said, I suspect the answer to your real question is "no." > > Ian > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f7a6221a-aada-4f3a-ab12-34d26f550e87%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
