What does the following generics code fail to compile? “`java List ints = new ArrayList(); List nums = ints; // Compile error? “`

Java Professional Hard

Java Professional — Hard

What does the following generics code fail to compile? “`java List ints = new ArrayList(); List nums = ints; // Compile error? “`

Key points

  • Java generics are invariant, not covariant
  • Subtyping rules apply to generics
  • List and List are not interchangeable

Ready to go further?

Related questions