test/tools/javac/literals/BadUnderscoreLiterals.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * @test /nodynamiccopyright/
aoqi@0 3 * @bug 6860973
aoqi@0 4 * @summary Project Coin: underscores in literals
aoqi@0 5 *
aoqi@0 6 * @compile/fail BadUnderscoreLiterals.java
aoqi@0 7 * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java
aoqi@0 8 *
aoqi@0 9 * @compile/fail -source 6 BadUnderscoreLiterals.java
aoqi@0 10 * @compile/fail/ref=BadUnderscoreLiterals.6.out -XDrawDiagnostics -source 6 -Xlint:-options BadUnderscoreLiterals.java
aoqi@0 11 */
aoqi@0 12
aoqi@0 13 public class BadUnderscoreLiterals {
aoqi@0 14 int valid = 1_1; // valid literal; illegal in -source 6
aoqi@0 15
aoqi@0 16 // test zero
aoqi@0 17 int z1 = _0; // valid (but undefined) variable
aoqi@0 18 int z2 = 0_; // trailing underscore
aoqi@0 19
aoqi@0 20 // test simple (decimal) integers
aoqi@0 21 int i1 = _1_2_3; // valid (but undefined) variable
aoqi@0 22 int i2 = 1_2_3_; // trailing underscore
aoqi@0 23
aoqi@0 24 // test binary integers
aoqi@0 25 int b1 = 0b_0; // leading underscore after radix
aoqi@0 26 int b2 = 0b0_; // trailing underscore
aoqi@0 27
aoqi@0 28 // test hexadecimal integers
aoqi@0 29 int x1 = 0x_0; // leading underscore after radix
aoqi@0 30 int x2 = 0x0_; // trailing underscore
aoqi@0 31
aoqi@0 32 // test floating point numbers
aoqi@0 33 float f1 = 0_.1; // trailing underscore before decimal point
aoqi@0 34 float f2 = 0._1; // leading underscore after decimal point
aoqi@0 35 float f3 = 0.1_; // trailing underscore
aoqi@0 36 float f4 = 0.1_e0; // trailing underscore before exponent
aoqi@0 37 float f5 = 0e_1; // leading underscore in exponent
aoqi@0 38 float f6 = 0e1_; // trailing underscore in exponent
aoqi@0 39
aoqi@0 40 // hexadecimal floating point
aoqi@0 41 float xf1 = 0x_0.1p0; // leading underscore after radix
aoqi@0 42 float xf2 = 0x0_.1p0; // trailing underscore before decimal point
aoqi@0 43 float xf3 = 0x0._1p0; // leading underscore after decimal point
aoqi@0 44 float xf4 = 0x0.1_p0; // trailing underscore before exponent
aoqi@0 45 float xf5 = 0x0p_1; // leading underscore after exponent
aoqi@0 46 float xf6 = 0x0p1_; // trailing underscore
aoqi@0 47 }
aoqi@0 48

mercurial