Skip to content
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
153d376
Separate identifiers into its own section. Clean up variables.
jdconrad Apr 17, 2018
6729d5f
More docs.
jdconrad Apr 18, 2018
84048e4
Merge branch 'master' into docs1
jdconrad Apr 18, 2018
10fca6c
Merge branch 'master' into docs1
jdconrad Apr 18, 2018
c2c3448
Modify language used to describe shallow copies.
jdconrad Apr 19, 2018
1cdf013
Move examples into lists to make sections flow better when multiple
jdconrad Apr 19, 2018
862962b
Update primitive types.
jdconrad Apr 20, 2018
73883ac
Cleaned up reference types.
jdconrad Apr 24, 2018
7dfb034
Clean up dynamic types.
jdconrad Apr 24, 2018
75f1498
String and void type clean up.
jdconrad Apr 25, 2018
f75d50e
Merge branch 'master' into docs2
jdconrad Apr 25, 2018
956a188
Merge branch 'master' into docs2
jdconrad Apr 27, 2018
bce78ed
Fixes.
jdconrad Apr 28, 2018
b034cff
Merge branch 'master' into docs2
jdconrad Apr 30, 2018
e82a1e0
Clean up types section.
jdconrad May 1, 2018
1da1704
Merge branch 'master' into docs2
jdconrad May 1, 2018
48b3aee
Merge branch 'master' into docs3
jdconrad May 2, 2018
8bc0c74
Some casting and example clean up.
jdconrad May 4, 2018
275c2e7
Merge branch 'master' into docs3
jdconrad May 4, 2018
00ba531
Updated examples.
jdconrad May 4, 2018
7bcd114
More changes.
jdconrad May 7, 2018
84ea43d
Merge branch 'master' into docs3
jdconrad May 8, 2018
1cf2f0b
Merge branch 'master' into docs3
jdconrad May 9, 2018
68059ae
More example clean up.
jdconrad May 9, 2018
73a24f0
More casting clean up.
jdconrad May 9, 2018
c3fcd67
More clean up.
jdconrad May 10, 2018
19abc56
More changes.
jdconrad May 14, 2018
00cf5df
Merge branch 'master' into docs3
jdconrad May 14, 2018
0cb3e66
More fixes.
jdconrad May 14, 2018
bc4509f
Merge branch 'master' into docs3
jdconrad May 14, 2018
507ac48
More example clean up.
jdconrad May 15, 2018
7ad4ebb
More changes.
jdconrad May 15, 2018
a9c941e
Finished promotion and boxing/unboxing.
jdconrad May 15, 2018
0007d26
Merge branch 'master' into docs2
jdconrad May 15, 2018
988fc23
Cleaned up casting basic on PR comments.
jdconrad May 19, 2018
b95ce25
More changes.
jdconrad May 21, 2018
a8ed00b
Merge branch 'master' into docs2
jdconrad May 21, 2018
7b73010
More fixes.
jdconrad May 21, 2018
8fc4566
Fixed casting and types based on PR feedback.
jdconrad May 22, 2018
ca2bb83
Cleaned up more.
jdconrad May 22, 2018
ae1ae75
Extra blank lines at end of docs.
jdconrad May 22, 2018
a5cc47a
Merge branch 'master' into docs2
jdconrad May 22, 2018
7b70e15
Start of structural change for operators.
jdconrad May 22, 2018
093a10f
Moved operations to the appropriate pages.
jdconrad May 23, 2018
bb4dc1c
More clean up.
jdconrad May 23, 2018
8f9b09e
Merge branch 'master' into docs5
jdconrad May 24, 2018
a122212
Added a casting table.
jdconrad May 24, 2018
2665835
Switch assign/access to store/load in examples.
jdconrad May 24, 2018
aeb879b
Cleaned up some of the general operators.
jdconrad May 24, 2018
7165b0f
Merge branch 'master' into docs5
jdconrad May 29, 2018
ba4b7c1
Merge branch 'master' into docs5
jdconrad May 30, 2018
b0c2512
Merge branch 'master' into docs5
jdconrad May 31, 2018
b1d31d1
Clean up of general operators.
jdconrad May 31, 2018
246c824
Fix examples with load from instead of load.
jdconrad May 31, 2018
4e2b89d
Update structure for long-term spec goals.
jdconrad May 31, 2018
8b5316b
Merge branch 'master' into docs5
jdconrad May 31, 2018
8302de3
Clean up numerical operators.
jdconrad Jun 1, 2018
7ad8379
Merge branch 'master' into docs5
jdconrad Jun 1, 2018
1d64edd
Merge branch 'docs5' into docs6
jdconrad Jun 1, 2018
0696c83
Partially completed clean up of reference type operators.
jdconrad Jun 1, 2018
46a868e
Completion of clean up of reference type operators.
jdconrad Jun 2, 2018
15aac91
Clean up of array operators section.
jdconrad Jun 2, 2018
f85e235
Partially completed boolean operators clean up.
jdconrad Jun 2, 2018
6f16058
More clean up.
jdconrad Jun 2, 2018
775cfff
More clean up.
jdconrad Jun 2, 2018
610d67c
Completion of operators clean up.
jdconrad Jun 2, 2018
3b8da65
Fix Java to Painless.
jdconrad Jun 2, 2018
33b7357
Merge branch 'master' into docs5
jdconrad Jun 2, 2018
d17c365
Merge branch 'master' into docs5
jdconrad Jun 3, 2018
a2afc62
Merge branch 'docs5' into docs6
jdconrad Jun 3, 2018
8c87bf9
Merge branch 'docs6' into docs7
jdconrad Jun 3, 2018
5b19038
Merge branch 'docs7' into docs8
jdconrad Jun 3, 2018
46f737f
Merge branch 'docs8' into docs9
jdconrad Jun 3, 2018
9439b92
Fix missing lang.
jdconrad Jun 3, 2018
5aaa88a
Merge branch 'docs5' into docs6
jdconrad Jun 3, 2018
86591c3
Merge branch 'docs6' into docs7
jdconrad Jun 3, 2018
d54e4a0
Fix missing lang.
jdconrad Jun 3, 2018
23c2320
Merge branch 'docs7' into docs8
jdconrad Jun 3, 2018
fba0246
Merge branch 'docs8' into docs9
jdconrad Jun 3, 2018
73ff8a2
Fix missing lang.
jdconrad Jun 4, 2018
2b55029
Merge branch 'master' into docs5
jdconrad Jun 4, 2018
bdb8eb1
Merge branch 'docs5' into docs6
jdconrad Jun 4, 2018
4e2994a
Merge branch 'docs6' into docs7
jdconrad Jun 4, 2018
a570d37
Merge branch 'docs7' into docs8
jdconrad Jun 4, 2018
2e38982
Merge branch 'docs8' into docs9
jdconrad Jun 4, 2018
c688199
Response to PR review.
jdconrad Jun 5, 2018
542f52e
Merge branch 'master' into docs5
jdconrad Jun 5, 2018
e0e7dce
Merge branch 'docs5' into docs6
jdconrad Jun 5, 2018
603e5e5
PR response to numeric operators.
jdconrad Jun 5, 2018
afdc961
Merge branch 'docs6' into docs7
jdconrad Jun 5, 2018
12fb54d
Response to PR comments for reference operators.
jdconrad Jun 5, 2018
c83ecaf
Merge branch 'docs7' into docs8
jdconrad Jun 5, 2018
be37bf1
Cleaned up array operators based on PR feedback.
jdconrad Jun 5, 2018
f0bd472
Merge branch 'docs8' into docs9
jdconrad Jun 5, 2018
c35e977
Clean up boolean operators based on PR feedback.
jdconrad Jun 5, 2018
0760a41
Accidentally left in modified test.
jdconrad Jun 5, 2018
c361792
Response to more PR feedback.
jdconrad Jun 7, 2018
038dd80
Merge branch 'master' into docs5
jdconrad Jun 7, 2018
d20d5d8
Merge branch 'master' into docs5
jdconrad Jun 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 127 additions & 61 deletions docs/painless/painless-casting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ during certain <<painless-operators, operations>>. An explicit cast specifies
the target type and forcefully occurs as its own operation. Use the *cast
operator* to specify an explicit cast.

Refer to the <<allowed-casts, cast table>> for a quick reference on all
allowed casts.

*Errors*

* If during a cast there exists no equivalent value for the target type.
Expand All @@ -31,15 +34,15 @@ cast: '(' TYPE ')' expression
+
<1> declare `int i`;
explicit cast `long 5` to `int 5` -> `int 5`;
assign `int 5` to `i`
store `int 5` to `i`
<2> declare `Map m`;
allocate `HashMap` instance -> `HashMap reference`;
implicit cast `HashMap reference` to `Map reference` -> `Map reference`;
assign `Map reference` to `m`
store `Map reference` to `m`
<3> declare `HashMap hm`;
access `m` -> `Map reference`;
load from `m` -> `Map reference`;
explicit cast `Map reference` to `HashMap reference` -> `HashMap reference`;
assign `HashMap reference` to `hm`
store `HashMap reference` to `hm`

[[numeric-type-casting]]
==== Numeric Type Casting
Expand Down Expand Up @@ -78,19 +81,19 @@ following table:
----
+
<1> declare `int a`;
assign `int 1` to `a`
store `int 1` to `a`
<2> declare `long b`;
access `a` -> `int 1`;
load from `a` -> `int 1`;
implicit cast `int 1` to `long 1` -> `long 1`;
assign `long 1` to `b`
store `long 1` to `b`
<3> declare `short c`;
access `b` -> `long 1`;
load from `b` -> `long 1`;
explicit cast `long 1` to `short 1` -> `short 1`;
assign `short 1` value to `c`
store `short 1` value to `c`
<4> declare `double e`;
access `a` -> `int 1`;
load from `a` -> `int 1`;
explicit cast `int 1` to `double 1.0`;
assign `double 1.0` to `e`;
store `double 1.0` to `e`;
(note the explicit cast is extraneous since an implicit cast is valid)
+
* Invalid numeric type casts resulting in errors.
Expand All @@ -106,9 +109,9 @@ following table:
*error* -> cannot implicit cast `double 1.0` to `int 1`;
(note an explicit cast is valid)
<2> declare `int b`;
assign `int 2` to `b`
store `int 2` to `b`
<3> declare byte `c`;
access `b` -> `int 2`;
load from `b` -> `int 2`;
*error* -> cannot implicit cast `int 2` to `byte 2`;
(note an explicit cast is valid)

Expand Down Expand Up @@ -136,21 +139,21 @@ or the target type is a descendant of the original type.
----
+
<1> declare `List x`;
assign default value `null` to `x`
store default value `null` to `x`
<2> declare `ArrayList y`;
allocate `ArrayList` instance -> `ArrayList reference`;
assign `ArrayList reference` to `y`;
<3> access `y` -> `ArrayList reference`;
store `ArrayList reference` to `y`;
<3> load from `y` -> `ArrayList reference`;
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
assign `List reference` to `x`;
store `List reference` to `x`;
(note `ArrayList` is a descendant of `List`)
<4> access `x` -> `List reference`;
<4> load from `x` -> `List reference`;
explicit cast `List reference` to `ArrayList reference`
-> `ArrayList reference`;
assign `ArrayList reference` to `y`;
<5> access `y` -> `ArrayList reference`;
store `ArrayList reference` to `y`;
<5> load from `y` -> `ArrayList reference`;
explicit cast `ArrayList reference` to `List reference` -> `List reference`;
assign `List reference` to `x`;
store `List reference` to `x`;
(note the explicit cast is extraneous, and an implicit cast is valid)
+
* Invalid reference type casts resulting in errors.
Expand All @@ -165,13 +168,13 @@ or the target type is a descendant of the original type.
<1> declare `List x`;
allocate `ArrayList` instance -> `ArrayList reference`;
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
assign `List reference` to `x`
store `List reference` to `x`
<2> declare `ArrayList y`;
access `x` -> `List reference`;
load from `x` -> `List reference`;
*error* -> cannot implicit cast `List reference` to `ArrayList reference`;
(note an explicit cast is valid since `ArrayList` is a descendant of `List`)
<3> declare `ArrayList y`;
access `x` -> `List reference`;
load from `x` -> `List reference`;
*error* -> cannot explicit cast `List reference` to `Map reference`;
(note no cast would be valid since neither `List` nor `Map` is a descendant
of the other)
Expand Down Expand Up @@ -206,24 +209,24 @@ based on the current type value the `def` type value represents.
+
<1> declare `def d0`;
implicit cast `int 3` to `def`;
assign `int 3` to `d0`
store `int 3` to `d0`
<2> allocate `ArrayList` instance -> `ArrayList reference`;
implicit cast `ArrayList reference` to `def` -> `def`;
assign `def` to `d0`
store `def` to `d0`
<3> declare `Object o`;
allocate `HashMap` instance -> `HashMap reference`;
implicit cast `HashMap reference` to `Object reference`
-> `Object reference`;
assign `Object reference` to `o`
store `Object reference` to `o`
<4> declare `def d1`;
access `o` -> `Object reference`;
load from `o` -> `Object reference`;
implicit cast `Object reference` to `def` -> `def`;
assign `def` to `d1`
store `def` to `d1`
<5> declare `int i`;
access `d1` -> `def`;
load from `d1` -> `def`;
implicit cast `def` to `HashMap reference` -> HashMap reference`;
call `size` on `HashMap reference` -> `int 0`;
assign `int 0` to `i`;
store `int 0` to `i`;
(note `def` was implicit cast to `HashMap reference` since `HashMap` is the
child-most descendant type value that the `def` type value
represents)
Expand All @@ -242,29 +245,29 @@ based on the current type value the `def` type value represents.
+
<1> declare `def d`;
implicit cast `double 1.0` to `def` -> `def`;
assign `def` to `d`
store `def` to `d`
<2> declare `int i`;
access `d` -> `def`;
load from `d` -> `def`;
implicit cast `def` to `double 1.0` -> `double 1.0`;
explicit cast `double 1.0` to `int 1` -> `int 1`;
assign `int 1` to `i`;
store `int 1` to `i`;
(note the explicit cast is necessary since a `double` value cannot be
converted to an `int` value implicitly)
<3> assign `int 1` to `d`;
<3> store `int 1` to `d`;
(note the switch in the type `d` represents from `double` to `int`)
<4> declare `float i`;
access `d` -> `def`;
load from `d` -> `def`;
implicit cast `def` to `int 1` -> `int 1`;
implicit cast `int 1` to `float 1.0` -> `float 1.0`;
assign `float 1.0` to `f`
store `float 1.0` to `f`
<5> allocate `ArrayList` instance -> `ArrayList reference`;
assign `ArrayList reference` to `d`;
store `ArrayList reference` to `d`;
(note the switch in the type `d` represents from `int` to `ArrayList`)
<6> declare `List l`;
access `d` -> `def`;
load from `d` -> `def`;
implicit cast `def` to `ArrayList reference` -> `ArrayList reference`;
implicit cast `ArrayList reference` to `List reference` -> `List reference`;
assign `List reference` to `l`
store `List reference` to `l`
+
* Invalid dynamic type casts resulting in errors.
+
Expand All @@ -277,17 +280,17 @@ based on the current type value the `def` type value represents.
----
<1> declare `def d`;
implicit cast `int 1` to `def` -> `def`;
assign `def` to `d`
store `def` to `d`
<2> declare `short s`;
access `d` -> `def`;
load from `d` -> `def`;
implicit cast `def` to `int 1` -> `int 1`;
*error* -> cannot implicit cast `int 1` to `short 1`;
(note an explicit cast is valid)
<3> allocate `HashMap` instance -> `HashMap reference`;
implicit cast `HashMap reference` to `def` -> `def`;
assign `def` to `d`
store `def` to `d`
<4> declare `List l`;
access `d` -> `def`;
load from `d` -> `def`;
implicit cast `def` to `HashMap reference`;
*error* -> cannot implicit cast `HashMap reference` to `List reference`;
(note no cast would be valid since neither `HashMap` nor `List` is a
Expand Down Expand Up @@ -316,9 +319,9 @@ Use the *cast operator* to convert a <<string-type, `String` type>> value into a
+
<1> declare `char c`;
explicit cast `String "C"` to `char C` -> `char C`;
assign `char C` to `c`
store `char C` to `c`
<2> explicit cast `String 'c'` to `char c` -> `char c`;
assign `char c` to `c`
store `char c` to `c`
+
* Casting a `String` reference into a `char` value.
+
Expand All @@ -328,11 +331,11 @@ Use the *cast operator* to convert a <<string-type, `String` type>> value into a
<2> char c = (char)s;
----
<1> declare `String s`;
assign `String "s"` to `s`;
store `String "s"` to `s`;
<2> declare `char c`
access `s` -> `String "s"`;
load from `s` -> `String "s"`;
explicit cast `String "s"` to `char s` -> `char s`;
assign `char s` to `c`
store `char s` to `c`

[[boxing-unboxing]]
==== Boxing and Unboxing
Expand Down Expand Up @@ -372,22 +375,22 @@ value and vice versa.
+
<1> declare `List l`;
allocate `ArrayList` instance -> `ArrayList reference`;
assign `ArrayList reference` to `l`;
<2> access `l` -> `List reference`;
store `ArrayList reference` to `l`;
<2> load from `l` -> `List reference`;
implicit cast `int 1` to `def` -> `def`;
call `add` on `List reference` with arguments (`def`);
(note internally `int 1` is boxed to `Integer 1` to store as a `def` type
value)
<3> declare `Integer I`;
call `valueOf` on `Integer` with arguments of (`int 0`) -> `Integer 0`;
assign `Integer 0` to `I`;
store `Integer 0` to `I`;
<4> declare `int i`;
access `I` -> `Integer 0`;
load from `I` -> `Integer 0`;
unbox `Integer 0` -> `int 0`;
access `l` -> `List reference`;
load from `l` -> `List reference`;
call `get` on `List reference` with arguments (`int 0`) -> `def`;
implicit cast `def` to `int 1` -> `int 1`;
assign `int 1` to `i`;
store `int 1` to `i`;
(note internally `int 1` is unboxed from `Integer 1` when loaded from a
`def` type value)
+
Expand Down Expand Up @@ -438,19 +441,82 @@ type value is derived from what the `def` type value represents at run-time.
<3> float f = x + 2.0F;
----
<1> declare `double d`;
promote `int 2` and `double 2.0 @0` -> `double 2.0 @0`;
promote `int 2` and `double 2.0 @0`: result `double`;
implicit cast `int 2` to `double 2.0 @1` -> `double 2.0 @1`;
add `double 2.0 @1` and `double 2.0 @0` -> `double 4.0`;
assign `double 4.0` to `d`
store `double 4.0` to `d`
<2> declare `def x`;
implicit cast `int 1` to `def` -> `def`;
assign `def` to `x`;
store `def` to `x`;
<3> declare `float f`;
access `x` -> `def`;
load from `x` -> `def`;
implicit cast `def` to `int 1` -> `int 1`;
promote `int 1` and `float 2.0` -> `float 2.0`;
promote `int 1` and `float 2.0`: result `float`;
implicit cast `int 1` to `float 1.0` -> `float `1.0`;
add `float 1.0` and `float 2.0` -> `float 3.0`;
assign `float 3.0` to `f`;
store `float 3.0` to `f`;
(note this example illustrates promotion done at run-time as promotion
done at compile-time would have resolved to a `def` type value)

[[allowed-casts]]
==== Allowed Casts

The following tables list all allowed casts read as row (original type) to
column (target type) with implicit as `I`, explicit as `E`, and not allowed as
`-`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably split this up. "The following tables show all allowed casts. Read the tables row by row, where the original type is shown in the first column, and each subsequent column indicates whether a cast to the specified type can be implicit (I), explicit (E), or is not allowed (-)."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.


*Primitive/Reference Types*

[cols="<3,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1"]
|====
| | o | b | s | c | i | j | f | d | O | B | S | C | I | L | F | D | T | R | def
| boolean ( o ) | | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | I
| byte ( b ) | - | | I | I | I | I | I | I | - | - | - | - | - | - | - | - | - | - | I
| short ( s ) | - | E | | E | I | I | I | I | - | - | - | - | - | - | - | - | - | - | I
| char ( c ) | - | E | E | | I | I | I | I | - | - | - | - | - | - | - | - | E | - | I
| int ( i ) | - | E | E | E | | I | I | I | - | - | - | - | - | - | - | - | - | - | I
| long ( j ) | - | E | E | E | E | | I | I | - | - | - | - | - | - | - | - | - | - | I
| float ( f ) | - | E | E | E | E | E | | I | - | - | - | - | - | - | - | - | - | - | I
| double ( d ) | - | E | E | E | E | E | E | | - | - | - | - | - | - | - | - | - | - | I
| Boolean ( O ) | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | I
| Byte ( B ) | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | - | - | I
| Short ( S ) | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | - | I
| Character ( C ) | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | - | I
| Integer ( I ) | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | - | I
| Long ( L ) | - | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | - | I
| Float ( F ) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | - | I
| Double ( D ) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | | - | - | I
| String ( T ) | - | - | - | E | - | - | - | - | - | - | - | - | - | - | - | - | | - | I
| Reference ( R ) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | @ | I
|====

@ See <<reference-type-casting, reference type casting>> for allowed reference
type casts.

*`def` Type*

[cols="<3,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1,^1"]
|====
| | o | b | s | c | i | j | f | d | O | B | S | C | I | L | F | D | T | R | def
| def as boolean | I | - | - | - | - | - | - | - | I | - | - | - | - | - | - | - | - | - |
| def as byte | - | I | I | I | I | I | I | I | - | I | I | I | I | I | I | I | - | - |
| def as short | - | E | I | E | I | I | I | I | - | E | I | E | I | I | I | I | - | - |
| def as char | - | E | E | I | I | I | I | I | - | E | E | I | I | I | I | I | E | - |
| def as int | - | E | E | E | I | I | I | I | - | E | E | E | I | I | I | I | - | - |
| def as long | - | E | E | E | E | I | I | I | - | E | E | E | E | I | I | I | - | - |
| def as float | - | E | E | E | E | E | I | I | - | E | E | E | E | E | I | I | - | - |
| def as double | - | E | E | E | E | E | E | I | - | E | E | E | E | E | E | I | - | - |
| def as Boolean | I | - | - | - | - | - | - | - | I | - | - | - | | - | - | - | - | - |
| def as Byte | - | I | I | I | I | I | I | I | - | I | I | I | I | I | I | I | - | - |
| def as Short | - | E | I | E | I | I | I | I | - | E | I | E | I | I | I | I | - | - |
| def as Character | - | E | E | I | I | I | I | I | - | E | E | I | I | I | I | I | - | - |
| def as Integer | - | E | E | E | I | I | I | I | - | E | E | E | I | I | I | I | - | - |
| def as Long | - | E | E | E | E | I | I | I | - | E | E | E | E | I | I | I | - | - |
| def as Float | - | E | E | E | E | E | I | I | - | E | E | E | E | E | I | I | - | - |
| def as Double | - | E | E | E | E | E | E | I | - | E | E | E | E | E | E | I | - | - |
| def as String | - | - | - | E | - | - | - | - | - | - | - | - | - | - | - | - | I | - |
| def as Reference | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | @ |
|====

@ See <<reference-type-casting, reference type casting>> for allowed reference
type casts.
13 changes: 13 additions & 0 deletions docs/painless/painless-functions.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[painless-functions]]
=== Functions

You can declare functions at the beginning of a Painless script, for example:

[source,painless]
---------------------------------------------------------
boolean isNegative(def x) { x < 0 }
...
if (isNegative(someVar)) {
...
}
---------------------------------------------------------
Loading