Skip to content
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

why not get the method using reflect #39126

Closed
mlboy opened this issue May 18, 2020 · 2 comments
Closed

why not get the method using reflect #39126

mlboy opened this issue May 18, 2020 · 2 comments

Comments

@mlboy
Copy link

mlboy commented May 18, 2020

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

$ go version go1.13.8 darwin/amd64

Does this issue reproduce with the latest release?

package main

import (
	"fmt"
	"reflect"
)

type t1 struct{}

func (t *t1) Name() string {
	return "tbl_t1"
}
func main() {
	m := t1{}
	rv := reflect.ValueOf(m)
	fn := rv.MethodByName("Name")
	fmt.Println(fn)
        // <invalid reflect.Value> ??????
}

why not get the method ?

keep 2 point :
image

@D1CED
Copy link

D1CED commented May 18, 2020

You have to use m := &t1{}, because the method is declared on the pointer.

@martisch
Copy link
Contributor

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see: https://github.com/golang/go/wiki/Questions

@golang golang locked and limited conversation to collaborators May 18, 2021
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

4 participants