CodeGym/Kurso sa Java/Module 2: Java Core/Karagdagang mga aralin para sa antas

Karagdagang mga aralin para sa antas

Available

Ano ang mga generic sa Java?

Sa araling ito , pinag-uusapan natin ang tungkol sa generics. O sa halip, tungkol sa mga pangunahing kaalaman na kailangan mong malaman kapag sumisid sa mga generic: kung ano ang mga generic at bakit kailangan mo ang mga ito. Napakahalaga ng paksa, at tiyak na kailangan mong maunawaan ito. Pasulong!

Mga generic para sa mga pusa

Ang mga generic ay isang mahusay na tool upang matulungan ang mga developer na magpahiwatig ng karagdagang impormasyon sa compiler para sa kaligtasan at flexibility ng uri. Ang malalim na artikulong ito , na isinulat ng isang miyembro ng komunidad ng CodeGym, ay tumatagal ng isa pang lap sa "generics".

Uri ng bura

Ang araling ito ay nakatuon sa ilang mga tampok ng generics pati na rin ang mga pitfalls na lumitaw kapag nagtatrabaho sa kanila. Dahil ang mga generic ay hindi bahagi ng Java noong ginawa ang wika, naidagdag ang uri ng erasure. Ano yan? Aalamin natin ito.

Mga wildcard sa generics

Ang mga wildcard ay isang napakahalagang katangian ng mga generic at tiyak na nararapat sa isang hiwalay na aralin . Ito ay isang kawili-wili at simpleng paksa. magugustuhan mo yan :)

Paggamit ng varargs kapag nagtatrabaho sa generics

Ang paggamit ng mga varargs na may mga generic ay maaaring humantong sa medyo hindi kasiya-siyang mga kahihinatnan - tambak na polusyon. Sa araling ito , tinatapos namin ang aming pagtalakay sa iba't ibang katangian ng generics sa Java.

4
Gawain
Java Core,  antasaralin
Naka-lock
Something superfluous
Our program is once again full of unnecessary lines of code. Let's correct this blunder by removing all the extra methods, so that the program displays text (and only the text) that corresponds to the task conditions. By the way, you need to get used to this. Junior developers' special ability to create unnecessary code is pretty annoying to senior developers.
8
Gawain
Java Core,  antasaralin
Naka-lock
OOP: Method overloading
Let's display matrices in different ways, however we want. OOP gives us a wonderful tool for this: method overloading. Overload the printMatrix method in 8 different ways. You should end up with 10 different printMatrix methods.
4
Gawain
Java Core,  antasaralin
Naka-lock
OOP: Method overloading - Eliminating the superfluous
Not every overloaded method is useful. And so it is in this program. Look at the code and think about which implementation of the print method will be called. Then remove all the superfluous implementations of the method - and you're done.
4
Gawain
Java Core,  antasaralin
Naka-lock
Man or woman?
Something in this program isn't right... It seems to display the names of men, but not those of women. Put an end to the discrimination: change the printName method so that it runs for both man and woman. The method should have a single implementation.
4
Gawain
Java Core,  antasaralin
Naka-lock
Be gone, all that is unnecessary!
Again, we have extra lines in a program. They've resulted in a bug, because the program tries to call the add method for cases for which it is not implemented. We won't override the superfluous add methods this time. We'll do something simpler: delete the lines for which there is no implementation.
Mga komento
  • Sikat
  • Bago
  • Luma
Dapat kang naka-sign in upang mag-iwan ng komento
Wala pang komento ang page na ito