All language subtitles for 027 Step 3 - Getter_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

If a class has failed, you need to add getas.

The cars is private, as it should be.

This means we can't access the field from outside.

So in this lesson, we're going to to get her.

The dealership class has one field, so we need to add one Geter.

So should ever get her be called get cars.

I hope you guessed the answer no, because let's imagine a scenario where I only want to access the

car at index zero, get cars, would create copies of every object in the car's array, but I only need

one of them.

This is a waste of memory.

When you create new copies of objects, it's not free.

It takes up memory.

It takes up space in your computer.

And so what if my array has a thousand cars?

Are you going to copy a thousand car objects, return them for the sake of accessing one?

Once again, this is typical to a class that manages an array of objects.

You just never know how many objects are going to be inside of that array.

And so it doesn't make sense to return every object at once.

Instead, the gutter is going to return one car object from an index of your choice.

So inside your dealership class at the get or get car public, it's going to return a car object.

Its name will be Get Car and it will take one parameter, the index of the car you want to get.

Finally, return the car object found at the index chosen by the user.

And now we can access the cars that we want.

In Maine and get the car object at index zero.

And the GETER is going to return the card index zero.

Pretty simple.

Let's print the new car object and make sure everything works fine.

And nice, when you print an object, Java knows to check if there's a two string method that returns

a string of every field.

Sounds great, right?

Let's update the new cars, clarefield new car at color.

Blue.

And then we're going to access another copy of the car object that in zero and print that object instead.

Well, what happened, this is bad, I change the outside variable, but the object at Index zero,

the cars feel changed as well.

If you return the object, Jaba returns a copy of what's inside the element and what's inside is a reference.

The letter is supposed to protect your field, but it returns a reference that points directly to one

of the objects.

This defeats the purpose of a letter.

Now the outside variable and field share a reference to the same object.

This is the last reference trap, reference trap for your Geter should not return an object directly.

The pitfall is that the outside variable and field are going to share a reference to the same object.

The solution is simple return a new copy of the object.

This table is in your cheat sheet, so we're going to return a new car object.

And in brackets, put the source object you want to copy values from we would like to copy values from

the car object and the index chosen by the user and right after creating a new car object or passing

any source object so Java knows to run the copy constructor, that receives one as a parameter.

And it's going to copy every field value from the source object into the one we just created.

And then the GETER is going to return a new copy, which gives me comfort, because now I know that

there's no way any of the objects inside the cars field are going to leak across the gutter, keeps

our field safe by returning copies of the underlying car objects.

Anyways, run the code.

And sweet, changing the outside variable has no effect on the field.

That's because the getter returns a copy of the object we're trying to access first, it indexes an

object from the car's array, but it returns a copy of it.

Ultimately, the letter keeps your field safe.

Our field is now fully secure and private, there is no chance of it leaking access.

Once again, by following these beautiful tables, we made sure the code is strong and bulletproof.

All right, now we can remove the random variable we made.

And that's all.

In this lesson, we added a geter, the Geter get car returns, one car object at the index of your

choice.

It indexes an object from the car's array and then it returns a new copy of the object.

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