---
title: "面试题 数组长度可否赋值"
author: "J2EE大鸟"
date: "2013-03-07T10:06:05Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-03-07T11:03:20Z"
id: 1825249
url: "https://benworld.iteye.com/blog/1825249"
---

```
public class ArrayLength {

	public static void main(String[] args) {
		String a[] = new String[10];
		a.length = 15;
		System.out.println(a.length);
	}

}
```

 

数组长度不能赋值，在编译器中会造成编译错误：The final field array.length cannot be assigned

 

另外，在进行赋值操作时，左边要赋值的对象必须是声明的变量，否则会报The left-hand side of an assignment must be a variable 的编译错误