Xóa bài viết
Bạn có chắc chắn muốn xóa bài viết này không ?
Xóa bình luận
Bạn có chắc chắn muốn xóa bình luận này không ?
Kotlin Equality – Difference between “===” vs “==”
https://grokonez.com/kotlin/kotlin-equality-difference-referential-equality-vs-structural-equality
Kotlin Equality – Difference between “===” vs “==”
In the tutorial, Grokonez will introduce Kotlin Equality, the difference between ===
and ==
.
I. Kotlin Equality
We have 2 types of Kotlin equality:
- Referential equality with
===
operation - Structural equality with
==
operation1. Referential equality
Referential equality is used to check references with same pointing object. It represents with===
operation (negative form!==
).
// ###########################
// 1. referential equality
// ###########################
val str = "a"
val str1 = "a"
println(str===str1)
/*
true
-> a & b point to the same object
*/
val i = Integer(10)
val j = Integer(10)
println(i===j)
/*
false
-> i & j point to the difference objects
*/
val jack = Customer("Jack", 25)
var customer = jack;
println(jack === customer)
/*
true
-> Because 'jack' and 'customer' objects point to the same object
*/
customer = Customer("Jack", 25)
println(jack === customer)
/*
false
-> Because 'jack' and 'customer' objects point to the difference object
*/
2. Structural equality
Structural equality is used to check equality of objects by equals()
function with ==
operation (negative form !=
)
a==b
is translated to a?equals(b) ?: (b === null)
More at:
https://grokonez.com/kotlin/kotlin-equality-difference-referential-equality-vs-structural-equality
Kotlin Equality – Difference between “===” vs “==”
Bình luận

{{ comment.user.name }}
Bỏ hay
Hay

Cùng một tác giả

1
0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...

1
0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...

1
0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
Bài viết liên quan

0
0
https://grokonez.com/kotlin/kotlinreadwritecsvfileexample How to read/write CSV file in Kotlin In this tutorial, we're gonna look at examples tha...

0
0
Kotlin Spring Boot + Angular 6 CRUD HttpClient + MySQL example | Spring Data JPA + REST APIs example
https://grokonez.com/frontend/angular/angular6/kotlinspringbootangular6crudhttpclientmysqlexamplespringdatajparestapisexample Kotlin Spring Boot +...