0

In golang.org's official FAQ, under pointers there is this quote: "The insight is that although a pointer to a concrete type can satisfy an interface, with one exception a pointer to an interface can never satisfy an interface"

Out of curiosity, what is that exception to the above rule? i.e when can an interface pointer implement an interface?

1 Answer 1

1

Just below it says:

The one exception is that any value, even a pointer to an interface, can be assigned to a variable of empty interface type (interface{}). Even so, it's almost certainly a mistake if the value is a pointer to an interface; the result can be confusing.

Sign up to request clarification or add additional context in comments.

1 Comment

You are right, I just tested it and it runs OK. Thanks func main() { type I interface{} f := func(p interface{}) { fmt.Println("runs") } var i I = 1 f(&i) }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.