java中数字定义里面的下划线--起什么作用呢?
下文笔者将讲述数字文字中下划线的功能简介说明,如下所示:
实现思路: 数字下划线:用于定义数字时,便于对数字的理解 增强数值类型的可读性(编译时,会取消数字中下划线的定义) 注意事项: 下划线可在"数值整数部分"的任意位置例:
int x1 = _87; // This is an identifier, not a numeric literal. int x2 = 8_7; // OK. (Decimal literal) int x2 = 87_; // Illegal. (Underscores must always be between digits) int x3 = 9_8; // OK. (Decimal literal.) int x4 = 0_x87; // Illegal. Can’t put underscores in the “0x” radix prefix. int x5 = 0x_87; // Illegal. (Underscores must always be between digits) int x6 = 0x8_7; // OK. (Hexadecimal literal) int x6 = 0x87_; // Illegal. (Underscores must always be between digits) int x6 = 0x_; // Illegal. (Not valid with the underscore removed) int x7 = 0_87; // OK. (Octal literal) int x7 = 08_7; // OK. (Octal literal) int x8 = 087_; // Illegal. (Underscores must always be between digits)
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。