Equality and Deep Equality

WBOY
Release: 2024-02-06 09:10:04
forward
590 people have browsed it

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))
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!