คำตอบความแปรปรวน: ถ้า Dog เป็นประเภทย่อยของ Animal List<Dog> จะเป็นประเภทย่อยของ List<Animal> หรือไม่ ใน Kotlin ประเภททั่วไปจะไม่แปรผันตามค่าเริ่มต้น — List<Dog> ไม่ใช่ List<Animal> เพื่อความปลอดภัยในการเปลี่ยนแปลง ใช้ out (ตัวแปรร่วม) เมื่อคุณสร้างเฉพาะ T — อ่านอย่างเดียว ใช้ใน (ตรงกันข้าม) เมื่อคุณใช้ T เท่านั้น — เช่น Comparator<Animal> ที่ยอมรับ Comparator<Dog>

ออก — ผู้ผลิต
Full content is available with a subscription.
Get full access to all courses on the platform for one year with a single payment.
Unlike other platforms that charge per course, here you get everything for one price, and after one year of use there will be no automatic charge for the following year.