本文介绍了Java.变量名称长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档中我读到:

A variables name can be any legal identifier — an **unlimited-length** sequence of Unicode letters and digits

所以,我创建了这个类:

so, i created this class:

class Test{
public static void main(String args[])
{
int i=10;
}}

其中i - 不是i, c $ c> 3 000 000 chars
大小.java文件〜3M。

where i - its not i, its variable with name length - 3000000 chars.the size .java file ~3M.

我尝试编译此文件:

javac Test.java



在结果中我有 Test.class with size Test.class 4 bayts。

In result i have Test.class with size Test.class 4bayts.


  1. 真的尝试,名字 unlimited-length ??

  2. 编译器如何翻译我的变量名长度为3000000字符,结果我有这么小的 .class 文件?

  1. Its really try, that name unlimited-length??
  2. How compiler translate my variable name with length 3000000 chars, that in result i have so small .class file?


推荐答案

iiiiiii .. 是一个局部变量,从其他类访问。因此,其名称无关紧要;编译器不需要存储它。另外,编译器可能会查看你的代码,并确定 {int i = 10;} 实际上并不执行任何操作,可以替换为 {} ,因为这两个版本产生相同的程序输出(无)。

iiiiiii.. is a local variable, i.e. it cannot be accessed from other classes. Therefore, its name does not matter; the compiler does not need to store it. Additionally, the compiler may look at your code and determine that {int i = 10;} is not actually doing anything and can be replaced by {} since both versions produce the same program output (none).

这篇关于Java.变量名称长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 03:34