โค้ดยิม/หลักสูตรจาวา/โมดูล 2: Java Core/บทเรียนเพิ่มเติมสำหรับระดับ

บทเรียนเพิ่มเติมสำหรับระดับ

มีอยู่

generics ใน Java คืออะไร?

ในบทเรียนนี้เราพูดถึงยาชื่อสามัญ หรือมากกว่านั้น เกี่ยวกับพื้นฐานที่คุณจำเป็นต้องรู้เมื่อเจาะลึกเกี่ยวกับยาชื่อสามัญ: ยาชื่อสามัญคืออะไรและทำไมคุณถึงต้องการมันเลย หัวข้อนี้สำคัญมาก และคุณต้องเข้าใจอย่างแน่นอน ซึ่งไปข้างหน้า!

ยาสามัญสำหรับแมว

Generics เป็นเครื่องมือที่ยอดเยี่ยมในการช่วยนักพัฒนาแนะนำข้อมูลเพิ่มเติมให้กับคอมไพเลอร์เพื่อความปลอดภัยและความยืดหยุ่นของประเภท บทความเชิงลึกนี้เขียนโดยสมาชิกของชุมชน CodeGym กล่าวถึง "ยาสามัญ" อีกครั้ง

พิมพ์ลบ

บทเรียนนี้อุทิศให้กับคุณลักษณะบางอย่างของยาชื่อสามัญ ตลอดจนข้อผิดพลาดที่เกิดขึ้นเมื่อทำงานกับยาชื่อสามัญ เนื่องจาก generics ไม่ได้เป็นส่วนหนึ่งของ Java เมื่อสร้างภาษา จึงมีการเพิ่มการลบประเภท นั่นอะไร? เราจะคิดออก

สัญลักษณ์แทนในชื่อสามัญ

สัญลักษณ์แทนเป็นคุณสมบัติที่สำคัญมากของยาชื่อสามัญ และสมควรได้รับบทเรียนแยกต่างหาก นี่เป็นหัวข้อที่น่าสนใจและเรียบง่าย คุณจะรักมัน :)

ใช้ varargs เมื่อทำงานกับยาชื่อสามัญ

การใช้ varargs กับยาชื่อสามัญอาจนำไปสู่ผลที่ไม่พึงประสงค์ค่อนข้างมาก เช่น มลพิษกองโต ในบทนี้เราจะสรุปการอภิปรายเกี่ยวกับคุณสมบัติต่างๆ ของชื่อสามัญใน Java

4
งาน
Java Core,  ระดับบทเรียน
ล็อค
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
งาน
Java Core,  ระดับบทเรียน
ล็อค
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
งาน
Java Core,  ระดับบทเรียน
ล็อค
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
งาน
Java Core,  ระดับบทเรียน
ล็อค
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
งาน
Java Core,  ระดับบทเรียน
ล็อค
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.
ความคิดเห็น
  • เป็นที่นิยม
  • ใหม่
  • เก่า
คุณต้องลงชื่อเข้าใช้เพื่อแสดงความคิดเห็น
หน้านี้ยังไม่มีความคิดเห็นใด ๆ