Hacker News new | ask | show | jobs
by airplane 3493 days ago
Don't think the scenario perfectly fits because before generics you couldn't have a method that takes in an Array of Animal, just an Array.

Can a language could resolve this issue without generics or some other contract feature (which Java did later add), or without limiting the scope of array definitions and their use?

May be good to note that Array<Dog> doesn't actually extend Array<Animal>, so there shouldn't be any polymorphic usage between them, and the return statement and method call scenarios are compile time errors with proper generics.

1 comments

> before generics you couldn't have a method that takes in an Array of Animal, just an Array.

Arrays aren't generic types like ArrayList. Arrays are core language constructs parameterized by their element types. Array types are not erased in Java.