HashCode and Equals - Easy and comprehensive including coding samples

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Marcus, it's really nice and effective way to understand the equals and hashcode method. I spent entire day understanding the same but things are now clear in just 45 minutes. Thanks for this tutorial.

nitishjain
Автор

I have read Josh Bloch's Effective Java - epic book. But unfortunately, I glossed over this part. Marcus has really shined a light at a place few care about since we hit generate in the IDE and that could lead to bad consequences if we aren't careful. Truly great video.

avneet
Автор

Outstanding video. Triple thumbs up! As the saying goes, you learn something new everyday.

ggaass
Автор

thanks for taking time out of your personal time to explain this in such a great detail :)

simoo
Автор

As always cool little things here and there that are necessary to make everything work well in real life. Most people who like A.M. and P.M. instead of 00:00 --> 23:59 are the most likely to make mistakes between them, not the people who choose 0:00 --> 23:59 whenever they can. Similarly, people who are in love with inheritance and casually use it everywhere will probably most likely break symmetry of .equals(). without even realizing or thinking about it.
There are several other pretty good coverages of this in videos -- they generally forget that. I think the tell-tale is that they say instanceof() to check rather than comparing .getClass() return values.

jvsnyc
Автор

Marcus, for the overriden hashCode() method in the Car and Engine classes, the first statement is "int result = 1;" but for the SomeClass class, the first statment is "int result=0;". Why the difference? Thanks.

langeredward
Автор

Thanks for the Perfect in-depth explanation.

rangachanakyagade
Автор

A question regarding 27:40. Is there any real performance gain in splitting "if" blocks compared to making them a one big "or" expression? Clean code and scalability aspects aside.

Cube
Автор

Birkhan asked me: Do you mind asking you which IDE your using? I assume your using Intellij but i dont have the option to run 1 method just like you do in your tutorial! How did you manage this, are you using a plugin?

Yes, I am using IntelliJ in the beginning of my course (later I switched to Eclipse to also showcase that IDE).
I am writing JUnit tests. The IDE has a JUnit plugin, which will allow you to run only one test method - but this is something the plugin makes possible for you - it will still have to create a main method in the background, like any kind of program in Java (that does not run within a container which has its own main method again).

Consider starting the course from video 1. While this course is not a course about testing, I show some more details about my IDE and testing in general in the course.

MarcusBiel
Автор

Great video. One doubt.
Can you explain why the order in which hashcode is calculated should be same the way equals is implemented.

Twerqt
Автор

Excellent instruction.  I was having a hard time wrapping my head around the equals() override as well a hashCode() method, but your video really helped to clarify things.  One question:  why is it advantageous to leave the Object type parameter in the equals() override rather than just use the Car object type.

punated
Автор

Hi, and welcome to episode 22 of my free Java Video course. My name is Marcus Biel. In this episode I am going to talk about the two methods hashCode and equals. This tutorial concludes my presentation of all the methods of the java.lang.Object class. hashCode and Equals both follow a contract, that ties them closely together, which is also why I am talking about both methods in just one episode. Knowing all the details about these two methods will make you a better programmer today, so get yourself some popcorn and listen carefully. Let’s start with the equals method. What does it do, what’s it useful for? The Equals method is used to compare two objects for equality, similar to the equals operator that is used for primitive values. But before going into much more detail, let’s first jump into my IDE and see this in action....

MarcusBiel
Автор

so much information and so great video . I like it

sendacool
Автор

Hi from 2019!) Is tthere still a follow up video? Cant open the link, unfortunately...

АлексейПлющов-иы
Автор

Hi Marcus! Great video. Since java8course.com is not found, where can I find your follow up/in depth HashCode video?

fallenIights
Автор

Excellent tutorial! I learned a lot particularly about the hashcode optimizations you mentioned towards the end. What particularly do you dislike about IDE-generated hashcodes? Is it the misuse and devs not discriminating which properties to use? Is it the lack of hashcode optimization which you presented? All the above?

tnield
Автор

Hi Marcus Biel
superb video I got much knowledge
Thankyou :)

dilipjain
Автор

Hi Marcus, this was really informative; but i couldn't find the link to the followup video on your blog. Is there a direct link for the same please. Thank you !

avinmacha
Автор

@Marcus,
Can you please explain, why hello1 and hello2 are equal, even though they are different Objects?

PaulusSh
Автор

First things first, cool stuff - more power to u Marcus.

In Car example following 2 checks :

if(obj == null){
return false;
}

if(getClass() != obj.getClass()){
return false;
}

Can be replaced with this single check right ?

if(!obj instanceOf Car){
return false; // as instanceOf takes care of null check too
}


#JustCurious

suman
visit shbcf.ru