Java - Why declare an array as a type of Interface?

The design "philosophy" is that you can't instantiate an array of a type parameter, so you have to instantiate the array with a type that is legal. The only available legal types known to the method are array of Object or of Comparable, and the latter captures more knowledge about the type.

You are allowed to downcast to an array of the type parameter, and the return type has to be that, so downcasting is required.

It's the "philosophy" of necessity.

Tags:

Java

Arrays