Details
Description
For details see http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001628.html
Some examples:
long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumbers = 999_99_9999L; float monetaryAmount = 12_345_132.12; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xFFEC_DE5E; long maxLong = 0x7fff_ffff_ffff_ffffL; long alsoMaxLong = 9_223_372_036_854_775_807L; double whyWouldYouEverDoThis = 0x1_.ffff_ffff_ffff_fp10_23; // Additionally, if binary literals are ever added to the Java language, the following might also be possible... byte nybbles = 0b0010_0101; long bytes = 0b11010010_01101001_10010100_10010010; int weirdBitfields = 0b000_10_101; // 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)
Activity
Robert Scholte
made changes -
Field | Original Value | New Value |
---|---|---|
Status | Open [ 1 ] | Resolved [ 5 ] |
Fix Version/s | 2.0 [ 15636 ] | |
Resolution | Fixed [ 1 ] |
First part done in rev. 1244
There's a newer version of the specs, although still informative
http://cr.openjdk.java.net/~darcy/ProjectCoin/ProjectCoin-Documentation-v0.83.html#literals