From ec75230b55281a84cd1a9aa52d33d5e552c82dd4 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Tue, 16 Aug 2016 11:10:36 -0700 Subject: [PATCH] reflect: document equality guarantee for Type The only previous mention of this property was in the String() method. Since this is the only way to uniquely identify a type and we can't change this property without breaking the Go 1 guarantee, it seems better to document this property than hiding it on a method. Fixes #16348 Change-Id: I3d25f7d6e6007e3c15c2e13010869888d0181fc2 Reviewed-on: https://go-review.googlesource.com/27170 Reviewed-by: Ian Lance Taylor --- src/reflect/type.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/reflect/type.go b/src/reflect/type.go index 891671017a..94c5d020c6 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -29,6 +29,12 @@ import ( // Use the Kind method to find out the kind of type before // calling kind-specific methods. Calling a method // inappropriate to the kind of type causes a run-time panic. +// +// You can use == with reflect.Type values to check whether two types +// are the same. If T1 and T2 are Go types, and v1 and v2 are values of +// those types respectively, then reflect.TypeOf(v1) == reflect.TypeOf(v2) +// if and only if both (interface{})(v2).(T1) and (interface{})(v1).(T2) +// succeed. type Type interface { // Methods applicable to all types. -- 2.48.1