All language subtitles for 391 hashCode and the operator.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
hu Hungarian
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

In the last video we have written a test to check that job done from map returns a job with the correct

properties.

However when we run this test we got a failure with this error message and the problem here is that

the compiler doesn't know how to compare instances of type job because we haven't provided any quality

operator for our job class.

And because this is a custom class that we have created then we need to override two things in the base

object class called the hash code and the equality operator and these look like this.

We have a hash code and we have an equality operator.

So what are these things exactly.

And how do we use them.

Well the hash code is an integer representation of an object and we can open the documentation to learn

more about it.

And the useful thing to know here is that hash code must be the same for objects that are equal to each

other according to the operator equal.

And the hash code of an object should only change if the object changes in a way that affects equality.

OK.

So this explanation gives us a vague idea about hash code but how should it be implemented.

Well let's get back to our job file and in here we are going to use a special function called hash values

like this and we need to import dark UI to make use of this and to this function we need to pass all

the properties that we have in our job class.

So in this case it's I.D. and name and rate but our like this.

And just to be clear this is the way that hash code is implemented in the classes inside the flatter

SDK.

So I recommend that you use the same convention for your own classes.

Next we need to implement the equality operator.

And what I'm going to do now is to write some code and then I'm going to explain it.

So here I can type.

If and then identical.

And then this with other than return true.

And then if runtime type is not equal to other dot runtime type that return false.

And finally I mean to type final job other job equals other and then return by the equals other job

dot idea and name equals other job.

The name and rate for our equals other job.

Right.

Our like this.

And these is the way that the equality operator is implemented for classes in the the decay.

So the first condition is to check if these two references are in fact the same object in memory.

And in this case we can return true.

And the second track is to verify if the other object is of the same type as the current one.

And this is necessary because the equity the operator could be used to combat objects of different types.

And if this is the case then we return false.

And if we get to this line it means that the other object is of type job so we can assign it to a new

variable of type job.

And finally we return true if all the properties match.

So this is the correct way of implementing the equality operator.

And in general it is good practice to define the hash code and the equality operator for our own classes

because this means that we can compare them directly and now that we have done this.

We can run our test once again and this time we got a success.

And just to be clear what happens when we call expect is that the equality operator is called between

the left and the right hand side arguments and this works because we have implemented the equality operator

for the job class.

Before we move on I want to mention that adding the hash code and the equality operator for our classes

can be a bit tedious because this is a bit of boilerplate code that we need to add for each class.

And on top of that if we add or remove properties from our classes then we have to remember to update

the hash code and the equality operator and especially if we have a lot of model classes that this can

become a lot of work that is error prone.

So one alternative approach to this is to use code generation tools that automate the process of creating

and updating model classes.

However we will not go where coding generation in this course and you can research this topic yourself

if you're interested.

OK so let's continue on the next video.

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