问题
Quick novice question: I want to extend a class as an array, like so
public class Map extends Item[][]
{
}
Is this possible, am I going about it the wrong way? Thanks!
回答1:
Arrays are weird beasts. The have some properties, like length
but they are not a class, so you can't extend them like you are attempting.
I think you are better off using composition, i.e. create a class that contains an Item[][]
and then extend that class (if you need to, having one class might be enough)
来源:https://stackoverflow.com/questions/10914928/java-extend-class-as-array