Java的:扩展类数组 [英] Java: Extend class as array

查看:150
本文介绍了Java的:扩展类数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速新手提问:我想扩展一个类为一个数组,像这样

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!

推荐答案

数组是奇怪的野兽。在有一些特性,如长度,但他们不是一类,所以像你正试图不能扩展它们。

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)

这篇关于Java的:扩展类数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆