|
1 | 1 | [[painless-literals]] |
2 | 2 | === Literals |
3 | 3 |
|
4 | | -Use literals to specify different types of values directly in a script. |
| 4 | +Use a literal to specify a value directly in an |
| 5 | +<<painless-operators, operation>>. |
5 | 6 |
|
6 | 7 | [[integers]] |
7 | 8 | ==== Integers |
8 | 9 |
|
9 | | -Use integer literals to specify an integer value in decimal, octal, or hex |
10 | | -notation of the <<primitive-types, primitive types>> `int`, `long`, `float`, |
| 10 | +Use an integer literal to specify an integer type value in decimal, octal, or |
| 11 | +hex notation of a <<primitive-types, primitive type>> `int`, `long`, `float`, |
11 | 12 | or `double`. Use the following single letter designations to specify the |
12 | | -<<primitive-types, primitive type>>: `l` or `L` for `long`, `f` or `F` for |
13 | | -`float`, and `d` or `D` for `double`. If not specified, the type defaults to |
14 | | -`int`. Use `0` as a prefix to specify an integer literal as octal, and use |
15 | | -`0x` or `0X` as a prefix to specify an integer literal as hex. |
| 13 | +primitive type: `l` or `L` for `long`, `f` or `F` for `float`, and `d` or `D` |
| 14 | +for `double`. If not specified, the type defaults to `int`. Use `0` as a prefix |
| 15 | +to specify an integer literal as octal, and use `0x` or `0X` as a prefix to |
| 16 | +specify an integer literal as hex. |
16 | 17 |
|
17 | 18 | *Grammar* |
18 | 19 | [source,ANTLR4] |
@@ -46,11 +47,10 @@ HEX: '-'? '0' [xX] [0-9a-fA-F]+ [lL]?; |
46 | 47 | [[floats]] |
47 | 48 | ==== Floats |
48 | 49 |
|
49 | | -Use floating point literals to specify a floating point value of the |
50 | | -<<primitive-types, primitive types>> `float` or `double`. Use the following |
51 | | -single letter designations to specify the <<primitive-types, primitive type>>: |
52 | | -`f` or `F` for `float` and `d` or `D` for `double`. If not specified, the type defaults |
53 | | -to `double`. |
| 50 | +Use a floating point literal to specify a floating point type value of a |
| 51 | +<<primitive-types, primitive type>> `float` or `double`. Use the following |
| 52 | +single letter designations to specify the primitive type: `f` or `F` for `float` |
| 53 | +and `d` or `D` for `double`. If not specified, the type defaults to `double`. |
54 | 54 |
|
55 | 55 | *Grammar* |
56 | 56 | [source,ANTLR4] |
@@ -81,7 +81,7 @@ EXPONENT: ( [eE] [+\-]? [0-9]+ ); |
81 | 81 | [[strings]] |
82 | 82 | ==== Strings |
83 | 83 |
|
84 | | -Use string literals to specify <<string-type, String>> values with |
| 84 | +Use a string literal to specify a <<string-type, `String` type>> value with |
85 | 85 | either single-quotes or double-quotes. Use a `\"` token to include a |
86 | 86 | double-quote as part of a double-quoted string literal. Use a `\'` token to |
87 | 87 | include a single-quote as part of a single-quoted string literal. Use a `\\` |
@@ -117,26 +117,6 @@ STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' ) |
117 | 117 | [[characters]] |
118 | 118 | ==== Characters |
119 | 119 |
|
120 | | -Use the <<painless-casting, casting operator>> to convert string literals or |
121 | | -<<string-type, String>> values into <<primitive-types, char>> values. |
122 | | -<<string-type, String>> values converted into |
123 | | -<<primitive-types, char>> values must be exactly one character in length |
124 | | -or an error will occur. |
125 | | - |
126 | | -*Examples* |
127 | | - |
128 | | -* Casting string literals into <<primitive-types, char>> values. |
129 | | -+ |
130 | | -[source,Painless] |
131 | | ----- |
132 | | -(char)"C" |
133 | | -(char)'c' |
134 | | ----- |
135 | | -+ |
136 | | -* Casting a <<string-type, String>> value into a <<primitive-types, char>> value. |
137 | | -+ |
138 | | -[source,Painless] |
139 | | ----- |
140 | | -String s = "s"; |
141 | | -char c = (char)s; |
142 | | ----- |
| 120 | +A character literal cannot be specified directly. Instead, use the |
| 121 | +<<string-character-casting, cast operator>> to convert a `String` type value |
| 122 | +into a `char` type value. |
0 commit comments