paint-brush
How to use HashMap with Custom Keys (and Avoid Shooting Yourself in the Leg)by@artemsutulov
1,091 reads
1,091 reads

How to use HashMap with Custom Keys (and Avoid Shooting Yourself in the Leg)

by Artem Sutulov7mApril 8th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

When writing complex data processing, we often find hash tables very useful. But when you decide to use your object as a key, it’s elementary to implement it the wrong way. The problem is about the way we write our objects, and how we write them. It seems impossible to make this mistake - modify a key of HashMap. However, one day it could happen. For example, a user's role gets new permission throughout a business logic. After adding it, `hashCode` will change, and the user's data is gone. It seems a common problem: don't modify it, and it will be okay.

Company Mentioned

Mention Thumbnail
featured image - How to use HashMap with Custom Keys (and Avoid Shooting Yourself in the Leg)
Artem Sutulov HackerNoon profile picture
Artem Sutulov

Artem Sutulov

@artemsutulov

I'm a professional FullStack Software Engineer, currently working for Revolut as Software Engineer (Backend).

Learn More
LEARN MORE ABOUT @ARTEMSUTULOV'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Artem Sutulov HackerNoon profile picture
Artem Sutulov@artemsutulov
I'm a professional FullStack Software Engineer, currently working for Revolut as Software Engineer (Backend).

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite