Expression Reference

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

Array

Array Access Expression

Array accessArray

Given the following snippet of code:

We infer the following Typing map:

  • a is of type int[]

The Expression Tree for the highlighted expression is:

Array Instance Creation Expression

Array creationArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Array creation without dimensions and empty initializerArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Array creation with initializer but without dimensionsArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Array creation with initializerArrayAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Assignment

Assignment Expression

Simple assignment expressionAssignmentOperator

Given the following snippet of code:

We infer the following Typing map:

  • a is of type int

The Expression Tree for the highlighted expression is:

Compound assignment expressionAssignmentOperator

Given the following snippet of code:

We infer the following Typing map:

  • a is of type int

The Expression Tree for the highlighted expression is:

Literal

Boolean Literal

Boolean literalBooleanLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Character Literal

Charcter literalLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class Literal

Class literalTypeLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class literal with voidTypeLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Null Literal

Null literalNullLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Integer Literal

Integer literalNumberLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Floating-Point Literal

Floating-point literalNumberLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

String Literal

String literalStringLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

String literal with quotes insideStringLiteral

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Operator

Cast Expression

Cast expressionTypeOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Cast expression of cast expressionTypeOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Conditional Expression

Conditional expressionConditionalOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Instanceof Expression

Instanceof expressionTypeOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Postfix Expression

Postfix increment expressionNumberOperator

Given the following snippet of code:

We infer the following Typing map:

  • n is of type int

The Expression Tree for the highlighted expression is:

Postfix decrement expressionNumberOperator

Given the following snippet of code:

We infer the following Typing map:

  • n is of type int

The Expression Tree for the highlighted expression is:

Prefix Expression

Prefix increment expressionNumberOperator

Given the following snippet of code:

We infer the following Typing map:

  • a is of type int

The Expression Tree for the highlighted expression is:

Prefix decrement expressionNumberOperator

Given the following snippet of code:

We infer the following Typing map:

  • a is of type int

The Expression Tree for the highlighted expression is:

Prefix expression with unary plusNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Prefix expression with unary minusNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Unary bitwise complement expressionNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Unary logical complement expressionBooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix Expression

Infix expression with multiplication operatorNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with division operatorNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with remainder operatorNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with string concatenation operatorStringOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with string concatenation operator with just one String operandStringNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with additions and subtractionsNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with left shiftNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with signed right shiftNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with unsigned right shiftNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with numerical comparison operator <BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with numerical comparison operator <=BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with numerical comparison operator >BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with numerical comparison operator >=BooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with numerical equality operatorBooleanOperatorNumberEquality

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with boolean equality operatorBooleanOperatorEquality

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with reference equality operatorBooleanOperatorObjectReferenceEquality

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with integer bitwise operatorNumberOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with boolean and operatorBooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with boolean or operatorBooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with conditional-and operatorBooleanOperator

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Infix expression with conditional-or operatorBooleanOperator

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 argumentClassAllocationConstructor

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Class instance creation without argumentsClassAllocationConstructor

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Generic class instance creationClassAllocationConstructorPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Generic class instance creation with multiple type argumentsClassAllocationConstructorPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified class instance creationClassAllocationConstructor

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Anonymous class instance creationClassAllocationConstructorObject

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method Invocation

Method Invocation Expression

Method invocation on anonymous class instanceClassAllocationConstructorMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method call on field access using qualified class nameFieldMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method invocation on variableMethodCall

Given the following snippet of code:

We infer the following Typing map:

  • r is of type Random

The Expression Tree for the highlighted expression is:

Method invocation on class instance creation expressionClassAllocationMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Static method invocationMethodCallStatic

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Static method invocation with type argumentsMethodCallStaticPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Static method invocation on qualified nameMethodCallStatic

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method Reference

Instance Creation Reference Expression

Instance creation reference expressionMethodAllocation

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method Reference Expression

Method reference expressionMethodObject

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method reference expression with genericsMethodObjectPolymorphism

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Method reference expression on a typeMethodObject

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super Method Reference Expression

Super method referenceInheritanceMethod

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified super method referenceInheritanceMethod

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field Access

Field Access Expression

Field access without thisField

Given the following snippet of code:

We infer the following Typing map:

  • f is of type int

The Expression Tree for the highlighted expression is:

Field access on a variableField

Given the following snippet of code:

We infer the following Typing map:

  • c is of type C

The Expression Tree for the highlighted expression is:

Field accessField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Nested field accessField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access on instance of anonymous classField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access using qualified class nameField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access on enumField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Field access on interfaceField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda

Lambda Expression

Lambda expression without parentheses around parametersFunctionParameter

Given the following snippet of code:

We infer the following Typing map:

  • name is of type String

The Expression Tree for the highlighted expression is:

Lambda expression with no parameters and empty blockFunctionParameter

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda expression with empty blockFunctionParameter

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda expression with blockFunctionParameter

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Lambda expressionFunctionParameter

Given the following snippet of code:

We infer the following Typing map:

  • name is of type String

The Expression Tree for the highlighted expression is:

Lambda expression with typesFunctionParameterType

Given the following snippet of code:

We infer the following Typing map:

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

The Expression Tree for the highlighted expression is:

Lambda expression with qualified generic typesFunctionParameterTypePolymorphism

Given the following snippet of code:

We infer the following Typing map:

  • l is of type List<String>

The Expression Tree for the highlighted expression is:

This

This Expression

This expressionSelf

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

This expression with qualifierClassSelf

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super

Super Field Access Expression

Super field accessInheritanceField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified super field accessInheritanceField

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super Method Invocation Expression

Super method invocationInheritanceMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super method invocation with argumentsInheritanceMethodCallArgument

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Super method invocation with type argumentsInheritanceMethodCallArgumentType

Given the following snippet of code:

The Expression Tree for the highlighted expression is:

Qualified super method invocationInheritanceMethodCall

Given the following snippet of code:

The Expression Tree for the highlighted expression is: