< prev index next >

test/langtools/tools/javac/literals/BadUnderscoreLiterals.java

Print this page


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 6860973
   4  * @summary Project Coin: underscores in literals
   5  *
   6  * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java
   7  * @compile/fail/ref=BadUnderscoreLiterals.6.out -XDrawDiagnostics -source 6 -Xlint:-options BadUnderscoreLiterals.java
   8  */
   9 
  10 public class BadUnderscoreLiterals {
  11     int valid = 1_1;            // valid literal; illegal in -source 6
  12 
  13     // test zero
  14     int z1 = _0;                // valid (but undefined) variable
  15     int z2 = 0_;                // trailing underscore
  16 
  17     // test simple (decimal) integers
  18     int i1 = _1_2_3;            // valid (but undefined) variable
  19     int i2 = 1_2_3_;            // trailing underscore
  20 
  21     // test binary integers
  22     int b1 = 0b_0;              // leading underscore after radix
  23     int b2 = 0b0_;              // trailing underscore
  24 
  25     // test hexadecimal integers
  26     int x1 = 0x_0;              // leading underscore after radix
  27     int x2 = 0x0_;              // trailing underscore
  28 
  29     // test floating point numbers
  30     float f1 = 0_.1;            // trailing underscore before decimal point
  31     float f2 = 0._1;            // leading underscore after decimal point
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 6860973
   4  * @summary Project Coin: underscores in literals
   5  *
   6  * @compile/fail/ref=BadUnderscoreLiterals.7.out -XDrawDiagnostics BadUnderscoreLiterals.java

   7  */
   8 
   9 public class BadUnderscoreLiterals {
  10     int valid = 1_1;            // valid literal
  11 
  12     // test zero
  13     int z1 = _0;                // valid (but undefined) variable
  14     int z2 = 0_;                // trailing underscore
  15 
  16     // test simple (decimal) integers
  17     int i1 = _1_2_3;            // valid (but undefined) variable
  18     int i2 = 1_2_3_;            // trailing underscore
  19 
  20     // test binary integers
  21     int b1 = 0b_0;              // leading underscore after radix
  22     int b2 = 0b0_;              // trailing underscore
  23 
  24     // test hexadecimal integers
  25     int x1 = 0x_0;              // leading underscore after radix
  26     int x2 = 0x0_;              // trailing underscore
  27 
  28     // test floating point numbers
  29     float f1 = 0_.1;            // trailing underscore before decimal point
  30     float f2 = 0._1;            // leading underscore after decimal point
< prev index next >