java Integer.toString()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3335685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:22:13  来源:igfitidea点击:

Integer.toString()

java

提问by Manuel Selva

Why does the Integer.toString()method is implemented using String.valueOf(int i)instead of using directly static method Integer.toString(int i)which is called back by String.valueOf(int i)?

为什么该Integer.toString()方法是使用String.valueOf(int i)而不是直接使用Integer.toString(int i)由 回调的静态方法来实现的String.valueOf(int i)

Update: I am working with a Sun (Oracle now) jdk 1.6.0_12

更新:我正在使用 Sun(现在是 Oracle)jdk 1.6.0_12

回答by Stephen C

The reason is probably historical. The Java 1.0 release was made in a hurry to try to meet (what was perceived to be) a closing window of opportunity. Many mistakes were made in the API design. But by the time of Java 1.1, designers realized that fixing mistakes in the API could break existing programs, and alienate developers and users. So they opted for leaving mistakes (especially minor inconsistencies) unfixed.

原因很可能是历史原因。Java 1.0 版本的发布是为了迎接(被认为是)一个即将关闭的机会之窗。在 API 设计中犯了许多错误。但是到了 Java 1.1 时,设计人员意识到修复 API 中的错误可能会破坏现有程序,并疏远开发人员和用户。所以他们选择不修正错误(尤其是轻微的不一致)。

This is just one of those minor inconsistencies. It makes no difference in practice since the JIT compiler will inline the calls anyway.

这只是那些轻微的不一致之一。这在实践中没有区别,因为 JIT 编译器无论如何都会内联调用。