gpt4 book ai didi

数字文字中的 Java 7 下划线

转载 作者:IT老高 更新时间:2023-10-28 20:26:44 27 4
gpt4 key购买 nike

当我们必须使用 _ 来分隔数字中的数字时,我不明白以下我不能使用它的情况:

In positions where a string of digits is expected

(如 JDK7 指南 here 中所述)

一些例子?

最佳答案

您没有必须使用“_”,但您可以。提案中给出的示例包括信用卡号码、电话号码或简单的数字,在代码中使用分隔符是有意义的。

对于“在需要一串数字的位置”,它只是在它应该以数字开始(或结束)的地方。以下是一些示例。

Note that according to this proposal, underscores can only be placed between digits. They cannot be placed by themselves in positions where a string of digits would normally be expected:

int x1 = _52; // This is an identifier, not a numeric literal.

int x2 = 5_2; // OK. (Decimal literal)

int x2 = 52_; // Illegal. (Underscores must always be between digits)

int x3 = 5_______2; // OK. (Decimal literal.)

int x4 = 0_x52; // Illegal. Can't put underscores in the "0x" radix prefix.

int x5 = 0x_52; // Illegal. (Underscores must always be between digits)

int x6 = 0x5_2; // OK. (Hexadecimal literal)

int x6 = 0x52_; // Illegal. (Underscores must always be between digits)

int x6 = 0x_; // Illegal. (Not valid with the underscore removed)

int x7 = 0_52; // OK. (Octal literal)

int x7 = 05_2; // OK. (Octal literal)

int x8 = 052_; // Illegal. (Underscores must always be between digits)


资源:

关于数字文字中的 Java 7 下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6212558/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com