Skip to content

reflect: is there any way to compare the same method between different receiver ? #22563

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

Closed
szyhf opened this issue Nov 3, 2017 · 1 comment

Comments

@szyhf
Copy link

szyhf commented Nov 3, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/usr/local/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xq/b3m9nkcx6jlgmnsvyz8w_05r0000gn/T/go-build427161431=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I want to make a event-delegate framework for my job, and I want to compare the same method between different receiver, if it's any way to do that? Or if I can get the value of receiver (maybe by reflect) ?

I know func value is not comparable but I'm wondering if there any other way can do that ?

package main

import (
	"reflect"
)

type TEvent struct {
	Name string
}

func (this *TEvent) Changed() {
	println(this.Name)
}

func main() {
	t1 := TEvent{"T1"}
	t2 := TEvent{"T2"}
        
        // might use reflect to compare ?
	tMV1 := reflect.ValueOf(t1.Changed)
	tMV1-2 := reflect.ValueOf(t1.Changed)
	tMV2 := reflect.ValueOf(t2.Changed)
	
	// Want: compare `t1.Changed` and `t2.Changed` got false,
        // compare `t1.Changed` and `t1.Changed` got true.
}

What did you expect to see?

What did you see instead?

@ALTree
Copy link
Member

ALTree commented Nov 3, 2017

Hi,

the Go project does not use its bug tracker for general discussion or asking questions about the language. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!

Closing, since this is not a bug.

@ALTree ALTree closed this as completed Nov 3, 2017
@golang golang locked and limited conversation to collaborators Nov 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants