All language subtitles for 002 Overriding equals()_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

A class can override methods that it inherits.

You saw that the object class is the common ancestor of every class.

So every class inherits methods from the object class.

Now, a class can customize, it can override methods that it inherits.

So in this lesson, you're going to learn to override the equals method.

When the double equal operator is used for objects, it compares the references, it returns true if

the references are equal.

So inside main job, a person to equal to person.

And then check if person to double eagles person.

Run the debugger.

Person to any person share the same reference, so the double equals sign returns true.

Now what if I said person two equal to a copy of person?

We run the debugger.

Person to store is a reference that points to a new object, and because they don't share the same reference,

then the operator is going to determine that they're not equal.

That being said, never used a double equals sign to compare objects.

Remember, that object is the ancestor of every class.

So by default, our person class is going to inherit this equals method.

Let's use it and see what happens.

We'll check if person two equals person one.

Run the debugger.

They don't share the same references, they do share the same fields.

But it returns false.

If you have another look at the equals method that we're inheriting, it returns true only if the references

are equal.

So hear us saying this is no different than saying this person two equals person one.

You can even confirm this, relaunch the debugger.

And it steps into the equals method inside the object class.

And you can see that a default equals method that we're inheriting compares the references of two objects.

That's why we need to override the equals method.

Override means to change the logic of an inherited method, you're going to customize, you're going

to override the equals method for the person class.

You already know how to override an equals method.

You've done it a million times before.

All we have to do is replicate the signature of the equals method we're inheriting.

And here we can write to whatever we want, we could print high and return false.

But the point is, we overrode the equals method and JAV is now going to use this one instead, try

it out, run the debugger and it calls the equals method we overrode.

Now, there's a much easier way to override equals, just the right equals, and let Intellisense autocomplete

the method for you and beautiful.

Don't worry about what super is for now remove it.

And now we can customize the equals method, just like we always do, if the object being passed in

is No.

Return false.

If it's not an instance of the person class return false.

If it is typecast, the object to person.

And then compare the fields of the current object that's calling this method to the one that's being

passed in return, the Stone Age equals person H.

We're going to have to add some Gedda's first, let's do just that.

And good.

Now, the override annotation means we're overriding a method that we inherited.

You don't have to include it.

Remember, in the past, we never did, but you should leave it.

Because if you misspell the method, it's going to throw an error and say there's no method equal to

override, so that's good to have.

Now, if you rerun the code, the person object calls the overwritten equals method.

Let's recap, you overrode the equals method.

Override it means changing the logic of an inherited method when you override a method, Jarvis starts

using that one instead.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.