Expression Reference

How to represent the different kinds of Java expressions as Expression Trees

Excavator operator at work.

Array

Array Access Expression

Array access
Specification
Array

Given the following snippet of code:

From this context, we know that:

  • a is of type int[]

The Expression Tree for the highlighted expression is:

Array Instance Creation Expression

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Array creation without dimensions and empty initializer
Specification
ArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Array creation with initializer but without dimensions
Specification
ArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Array creation with initializer
Specification
ArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Assignment

Assignment Expression

Simple assignment expression
Specification
AssignmentOperator

Given the following snippet of code:

From this context, we know that:

  • a is of type int

The Expression Tree for the highlighted expression is:

Compound Assignment Expression

Compound assignment expression
Specification
AssignmentOperator

Given the following snippet of code:

From this context, we know that:

  • a is of type int

The Expression Tree for the highlighted expression is:

Literal

Boolean Literal

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Character Literal

Charcter literal
Specification
Literal

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class Literal

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class literal with void
Specification
TypeLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Null Literal

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Integer Literal

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Floating-Point Literal

Floating-point literal
Specification
NumberLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

String Literal

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

String literal with quotes inside
Specification
StringLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Cast

Cast Expression

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Cast expression of cast expression
Specification
TypeOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class Instance Creation

Class Instance Creation Expression

Class instance creation with argument
Specification
ClassAllocationConstructor

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class instance creation without arguments
Specification
ClassAllocationConstructor

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Generic class instance creation with multiple type arguments
Specification
ClassAllocationConstructorPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified class instance creation
Specification
ClassAllocationConstructor

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Anonymous-class instance creation
Specification
ClassAllocationConstructorObject

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method Invocation

Method Invocation Expression

Method invocation on anonymous-class instance
Specification
ClassAllocationConstructorMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method call on field access using qualified class name
Specification
FieldMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method invocation on variable
Specification
MethodCall

Given the following snippet of code:

From this context, we know that:

  • r is of type Random

The Expression Tree for the highlighted expression is:

Method invocation on class instance creation expression
Specification
ClassAllocationMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Static method invocation
Specification
MethodCallStatic

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Static method invocation with type arguments
Specification
MethodCallStaticPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Static method invocation on qualified name
Specification
MethodCallStatic

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super Method Invocation Expression

Super method invocation
Specification
InheritanceMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super method invocation with arguments
Specification
InheritanceMethodCallArgument

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super method invocation with type arguments
Specification
InheritanceMethodCallArgumentType

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified super method invocation
Specification
InheritanceMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Operator

Conditional Expression

Conditional expression
Specification
ConditionalOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Type Comparison Expression

Instanceof expression
Specification
TypeOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Postfix Increment Expression

Postfix increment expression
Specification
NumberOperator

Given the following snippet of code:

From this context, we know that:

  • n is of type int

The Expression Tree for the highlighted expression is:

Postfix Decrement Expression

Postfix decrement expression
Specification
NumberOperator

Given the following snippet of code:

From this context, we know that:

  • n is of type int

The Expression Tree for the highlighted expression is:

Prefix Increment Expression

Prefix increment expression
Specification
NumberOperator

Given the following snippet of code:

From this context, we know that:

  • a is of type int

The Expression Tree for the highlighted expression is:

Prefix Decrement Expression

Prefix decrement expression
Specification
NumberOperator

Given the following snippet of code:

From this context, we know that:

  • a is of type int

The Expression Tree for the highlighted expression is:

Unary Plus Expression

Prefix expression with unary plus
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Unary Minus Expression

Prefix expression with unary minus
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Unary Bitwise Complement Expression

Unary bitwise complement expression
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Unary Logical Complement Expression

Unary logical complement expression
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Addition Expression

Infix expression with additions and subtractions
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with addition denoting string concatenation
Specification
StringOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with addition denoting string concatenation with just one String operand
Specification
StringNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Subtraction Expression

Infix expression with additions and subtractions
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Multiplication Expression

Infix expression with multiplication operator
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Division Expression

Infix expression with division operator
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Remainder Expression

Infix expression with remainder operator
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Left Shift Expression

Infix expression with left shift
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Signed Right Shift Expression

Infix expression with signed right shift
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Unsigned Right Shift Expression

Infix expression with unsigned right shift
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Less-Than Relational Expression

Infix expression with numerical comparison operator <
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Less-Than-Or-Equal Relational Expression

Infix expression with numerical comparison operator <=
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Greater-Than Relational Expression

Infix expression with numerical comparison operator >
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Greater-Than-Or-Equal Relational Expression

Infix expression with numerical comparison operator >=
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Equal-To Expression

Infix expression with numerical equality operator
Specification
BooleanOperatorNumberEquality

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with boolean equality operator
Specification
BooleanOperatorEquality

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Not-Equal-To Expression

Infix expression with reference equality operator
Specification
BooleanOperatorObjectReferenceEquality

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Exclusive-Or Expression

Infix expression with integer bitwise operator
Specification
NumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

And Expression

Infix expression with boolean and operator
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Inclusive-Or Expression

Infix expression with boolean or operator
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Conditional-And Expression

Infix expression with conditional-and operator
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Conditional-Or Expression

Infix expression with conditional-or operator
Specification
BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method Reference

Constructor Reference Expression

Instance creation reference expression
Specification
MethodAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method Reference Expression

Method reference expression
Specification
MethodObject

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method reference expression with generics
Specification
MethodObjectPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method reference expression on a type
Specification
MethodObject

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super Method Reference Expression

Super method reference
Specification
InheritanceMethod

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified super method reference
Specification
InheritanceMethod

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Expression Name

Simple Expression Name

Instance variable access with simple name
Specification
FieldVariable

Given the following snippet of code:

From this context, we know that:

  • f is of type int

The Expression Tree for the highlighted expression is:

Qualified Expression Name

Field access denoted by Qualified Expression Name
Specification
FieldVariable

Given the following snippet of code:

From this context, we know that:

  • c is of type C

The Expression Tree for the highlighted expression is:

Field access denoted by Qualified Expression Name
Specification
FieldVariable

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access on enum denoted by Qualified Expression Name
Specification
FieldVariable

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access on interface denoted by Qualified Expression Name
Specification
FieldVariable

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field Access

Field Access Expression

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Nested field access
Specification
FieldVariable

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access on instance of anonymous class
Specification
FieldVariable

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super Field Access Expression

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified super field access
Specification
InheritanceField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda

Lambda Expression

Lambda expression without parentheses around parameters
Specification
FunctionParameter

Given the following snippet of code:

From this context, we know that:

  • name is of type String

The Expression Tree for the highlighted expression is:

Lambda expression with no parameters and empty block
Specification
FunctionParameter

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda expression with empty block
Specification
FunctionParameter

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda expression with block
Specification
FunctionParameter

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Given the following snippet of code:

From this context, we know that:

  • name is of type String

The Expression Tree for the highlighted expression is:

Lambda expression with types
Specification
FunctionParameterType

Given the following snippet of code:

From this context, we know that:

  • surname is of type String
  • name is of type String

The Expression Tree for the highlighted expression is:

Lambda expression with qualified generic types
Specification
FunctionParameterTypePolymorphism

Given the following snippet of code:

From this context, we know that:

  • l is of type List<String>

The Expression Tree for the highlighted expression is:

This

This Expression

This expression
Specification
Self

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified This Expression

This expression with qualifier
Specification
ClassSelf

Given the following snippet of code:

The Expression Tree for the highlighted expression is: