Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming usage

hashCode and equals

User Information

Report a typo

You’ve developed a beautiful cross-platform application used by many people. As a developer, you want to know if two of the users are the same, what operating systems they have installed, and so on. For this purpose, you've created the UserInfo class. In order to save all the necessary information in a convenient way, you want to create an equals method to send the information to the server. You know that two users are the same if their username and email are the same.

For example:

userInfo1 = Johnny-pepe@pepe.com
userInfo2 = Johnny-pepe@pepe.com
println(userInfo1 == userInfo2) // true

Sample Input 1:

Sample Output 1:

true
Write a program in Kotlin
class UserInfo(val userName: String, val email: String) {
override fun equals(other: Any?): Boolean {
// write your code here
}
}
___

Create a free account to access the full topic