yes, you can use Name / PgkPath methods to test equality.

https://golang.org/pkg/reflect/#Type

Those methods might be useful too,

        // Implements reports whether the type implements the interface type u.
        Implements(u Type <https://golang.org/pkg/reflect/#Type>) bool 
<https://golang.org/pkg/builtin/#bool>

        // AssignableTo reports whether a value of the type is assignable to 
type u.
        AssignableTo(u Type <https://golang.org/pkg/reflect/#Type>) bool 
<https://golang.org/pkg/builtin/#bool>

        // ConvertibleTo reports whether a value of the type is convertible to 
type u.
        ConvertibleTo(u Type <https://golang.org/pkg/reflect/#Type>) bool 
<https://golang.org/pkg/builtin/#bool>

And the doc says,


        // String returns a string representation of the type.
        // The string representation may use shortened package names
        // (e.g., base64 instead of "encoding/base64") and is not
        // guaranteed to be unique among types. To test for type identity,
        // compare the Types directly.
        String() string <https://golang.org/pkg/builtin/#string>


>compare the Types directly.

I understand it means you need to iterate field and methods to test more.


On Tuesday, May 2, 2017 at 4:47:37 AM UTC+2, nz wrote:
>
> Hi
>
> As far as I can tell two reflect.Type's should be equal, but they fail 
> equality (==) test, printing the reflect.Type using "%#v" of the types 
> yields identical values
>
> &reflect.rtype{size:0x8, ptrdata:0x8, hash:0xdd3884e8, tflag:0x1, 
> align:0x8, fieldAlign:0x8, kind:0x36, alg:(*reflect.typeAlg)(0x136b930), 
> gcdata:(*uint8)(0xd60948), str:145804, ptrToThis:0}
> &reflect.rtype{size:0x8, ptrdata:0x8, hash:0xdd3884e8, tflag:0x1, 
> align:0x8, fieldAlign:0x8, kind:0x36, alg:(*reflect.typeAlg)(0x136b930), 
> gcdata:(*uint8)(0xd60948), str:145804, ptrToThis:0}
>
> When I invoke them they appear to create the same instance (printing using 
> "%#v") -
> (**my.TestObject)(0xc420196140)
> (**my.TestObject)(0xc420196148)
>
> Yet equality between types fails ... Is there something else that I can 
> test for ?
>
> thanks
> Nz
>
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to