Home  >  Article  >  Backend Development  >  Equality and Deep Equality

Equality and Deep Equality

WBOY
WBOYforward
2024-02-06 09:10:04590browse

Equality and Deep Equality

Question content

Why is there a difference between Equal and DeepEqual?

s1 := "abc"
s2 := "abc"

sv1 := reflect.ValueOf(s1)
sv2 := reflect.ValueOf(s2)

fmt.Println(sv1.Equal(sv2))
fmt.Println(reflect.DeepEqual(sv1, sv2))

The first prints true and the second prints false.


Correct answer


reflect.DeepEqual seems to require some manual unboxing as it treats reflect.Values for structs instead of reflect.Values (reflect.DeepEqual(v1.Interface(), v2.Interface())">

The above is the detailed content of Equality and Deep Equality. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete