int [] x和有什么区别?和int x [] ;? [英] What is the difference between int[] x; and int x[];?

查看:96
本文介绍了int [] x和有什么区别?和int x [] ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
int []数组和int数组[]之间的区别

我确定已经问过这个问题,只是写了标题才能找到它,但令我惊讶的是没有.我正在处理一个问题,并且提出了这个问题.我试过了:

I was sure that this question is already asked and just wrote the title to find it, but to my surprise it wasn't. I was working on one issue and this question raised. I tried this:

int[] x = new int[1];
int y[] = new int[1];
x=y;
y=x;

并且编译器没有给我一个错误.那么这两个声明之间有什么区别吗?

and compiler didn't give me an error. So is there any difference between these two declarations?

推荐答案

语义没有区别.两种语法含义相同. JLS§10.2的一些摘录:

There is no difference in semantics. Both syntaxes mean the same. Some extract from the JLS §10.2:

[]可能会作为类型的一部分出现在声明,或作为特定变量的声明器的一部分,或两者皆有,如本例所示:

The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both, as in this example:

byte[] rowvector, colvector, matrix[];

此声明等效于:

byte rowvector[], colvector[], matrix[][];

但是,正如 Voo 在以下注释中指出的那样,在声明多个数组时,这些声明可能会引起一些棘手的混乱在一个语句中.

However, as Voo states in the below comments, there can be some tricky confusion about these declarations when declaring several arrays in a single statement.

这篇关于int [] x和有什么区别?和int x [] ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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