Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Extend class as array

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!

like image 860
Daniel Messias Avatar asked Dec 12 '22 01:12

Daniel Messias


1 Answers

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)

like image 89
hvgotcodes Avatar answered Jan 18 '23 22:01

hvgotcodes