NOTE: You are looking at documentation for an older release. For the latest information, see the current release documentation.
Operators: Boolean
editOperators: Boolean
editBoolean Not
editUse the boolean not operator '!'
to NOT a boolean
type value where true
is
flipped to false
and false
is flipped to true
.
Errors
-
If a value other than a
boolean
type value or a value that is castable to aboolean
type value is given.
Truth
original | result |
---|---|
true |
false |
false |
true |
Grammar
boolean_not: '!' expression;
Examples
-
Boolean not with the
boolean
type. -
Boolean not with the
def
type.
Greater Than
editUse the greater than operator '>'
to COMPARE two numeric type values where a
resultant boolean
type value is true
if the left-hand side value is greater
than to the right-hand side value and false
otherwise.
Errors
- If either the evaluated left-hand side or the evaluated right-hand side is a non-numeric value.
Grammar
greater_than: expression '>' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Greater than with different numeric types.
declare
boolean x
; greater thanint 5
andint 4
→boolean true
; storeboolean true
tox
;declare
double y
; storedouble 6.0
toy
;load from
y
→double 6.0 @0
; promoteint 6
anddouble 6.0
: resultdouble
; implicit castint 6
todouble 6.0 @1
→double 6.0 @1
; greater thandouble 6.0 @1
anddouble 6.0 @0
→boolean false
; storeboolean false
tox
-
Greater than with
def
type.declare
int x
; storeint 5
tox
declare
def y
; implicit castdouble 7.0
todef
→def
; storedef
toy
declare
def z
; load fromy
→def
; implicit castdef
todouble 7.0
→double 7.0
; greater thandouble 7.0
anddouble 6.5
→boolean true
; implicit castboolean true
todef
→def
; storedef
toz
declare
def a
; load fromy
→def
; implicit castdef
todouble 7.0
→double 7.0
; load fromx
→int 5
; promoteint 5
anddouble 7.0
: resultdouble
; implicit castint 5
todouble 5.0
→double 5.0
; greater thandouble 5.0
anddouble 7.0
→boolean false
; implicit castboolean false
todef
→def
; storedef
toz
Greater Than Or Equal
editUse the greater than or equal operator '>='
to COMPARE two numeric type values
where a resultant boolean
type value is true
if the left-hand side value is
greater than or equal to the right-hand side value and false
otherwise.
Errors
- If either the evaluated left-hand side or the evaluated right-hand side is a non-numeric value.
Grammar
greater_than_or_equal: expression '>=' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Greater than or equal with different numeric types.
declare
boolean x
; greater than or equalint 5
andint 4
→boolean true
; storeboolean true
tox
declare
double y
; storedouble 6.0
toy
load from
y
→double 6.0 @0
; promoteint 6
anddouble 6.0
: resultdouble
; implicit castint 6
todouble 6.0 @1
→double 6.0 @1
; greater than or equaldouble 6.0 @1
anddouble 6.0 @0
→boolean true
; storeboolean true
tox
-
Greater than or equal with the
def
type.declare
int x
; storeint 5
tox
;declare
def y
implicit castdouble 7.0
todef
→def
; storedef
toy
declare
def z
; load fromy
→def
; implicit castdef
todouble 7.0 @0
→double 7.0 @0
; greater than or equaldouble 7.0 @0
anddouble 7.0 @1
→boolean true
; implicit castboolean true
todef
→def
; storedef
toz
declare
def a
; load fromy
→def
; implicit castdef
todouble 7.0
→double 7.0
; load fromx
→int 5
; promoteint 5
anddouble 7.0
: resultdouble
; implicit castint 5
todouble 5.0
→double 5.0
; greater than or equaldouble 5.0
anddouble 7.0
→boolean false
; implicit castboolean false
todef
→def
; storedef
toz
Less Than
editUse the less than operator '<'
to COMPARE two numeric type values where a
resultant boolean
type value is true
if the left-hand side value is less
than to the right-hand side value and false
otherwise.
Errors
- If either the evaluated left-hand side or the evaluated right-hand side is a non-numeric value.
Grammar
less_than: expression '<' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Less than with different numeric types.
declare
boolean x
; less thanint 5
andint 4
→boolean false
; storeboolean false
tox
declare
double y
; storedouble 6.0
toy
load from
y
→double 6.0 @0
; promoteint 6
anddouble 6.0
: resultdouble
; implicit castint 6
todouble 6.0 @1
→double 6.0 @1
; less thandouble 6.0 @1
anddouble 6.0 @0
→boolean false
; storeboolean false
tox
-
Less than with the
def
type.declare
int x
; storeint 5
tox
declare
def y
; implicit castdouble 7.0
todef
→def
; storedef
toy
declare
def z
; load fromy
→def
; implicit castdef
todouble 7.0
→double 7.0
; less thandouble 7.0
anddouble 6.5
→boolean false
; implicit castboolean false
todef
→def
; storedef
toz
declare
def a
; load fromy
→def
; implicit castdef
todouble 7.0
→double 7.0
; load fromx
→int 5
; promoteint 5
anddouble 7.0
: resultdouble
; implicit castint 5
todouble 5.0
→double 5.0
; less thandouble 5.0
anddouble 7.0
→boolean true
; implicit castboolean true
todef
→def
; storedef
toz
Less Than Or Equal
editUse the less than or equal operator '<='
to COMPARE two numeric type values
where a resultant boolean
type value is true
if the left-hand side value is
less than or equal to the right-hand side value and false
otherwise.
Errors
- If either the evaluated left-hand side or the evaluated right-hand side is a non-numeric value.
Grammar
greater_than_or_equal: expression '<=' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Less than or equal with different numeric types.
declare
boolean x
; less than or equalint 5
andint 4
→boolean false
; storeboolean true
tox
declare
double y
; storedouble 6.0
toy
load from
y
→double 6.0 @0
; promoteint 6
anddouble 6.0
: resultdouble
; implicit castint 6
todouble 6.0 @1
→double 6.0 @1
; less than or equaldouble 6.0 @1
anddouble 6.0 @0
→boolean true
; storeboolean true
tox
-
Less than or equal with the
def
type.declare
int x
; storeint 5
tox
;declare
def y
; implicit castdouble 7.0
todef
→def
; storedef
toy
;declare
def z
; load fromy
→def
; implicit castdef
todouble 7.0 @0
→double 7.0 @0
; less than or equaldouble 7.0 @0
anddouble 7.0 @1
→boolean true
; implicit castboolean true
todef
→def
; storedef
toz
declare
def a
; load fromy
→def
; implicit castdef
todouble 7.0
→double 7.0
; load fromx
→int 5
; promoteint 5
anddouble 7.0
: resultdouble
; implicit castint 5
todouble 5.0
→double 5.0
; less than or equaldouble 5.0
anddouble 7.0
→boolean true
; implicit castboolean true
todef
→def
; storedef
toz
Instanceof
editUse the instanceof operator
to COMPARE the variable/field type to a
specified reference type using the reference type name where a resultant
boolean
type value is true
if the variable/field type is the same as or a
descendant of the specified reference type and false otherwise.
Errors
- If the reference type name doesn’t exist as specified by the right-hand side.
Grammar
instance_of: ID 'instanceof' TYPE;
Examples
-
Instance of with different reference types.
declare
Map m
; allocateHashMap
instance →HashMap reference
; implicit castHashMap reference
toMap reference
; storeMap reference
tom
declare
boolean a
; load fromm
→Map reference
; implicit castMap reference
toHashMap reference
→HashMap reference
; instanceofHashMap reference
andHashMap
→boolean true
; storeboolean true
toa
declare
boolean b
; load fromm
→Map reference
; implicit castMap reference
toHashMap reference
→HashMap reference
; instanceofHashMap reference
andMap
→boolean true
; storetrue
tob
; (noteHashMap
is a descendant ofMap
) -
Instance of with the
def
type.declare
def d
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
todef
→def
; storedef
tod
declare
boolean a
; load fromd
→def
; implicit castdef
toArrayList reference
→ArrayList reference
; instanceofArrayList reference
andList
→boolean true
; storeboolean true
toa
; (noteArrayList
is a descendant ofList
)declare
boolean b
; load fromd
→def
; implicit castdef
toArrayList reference
→ArrayList reference
; instanceofArrayList reference
andMap
→boolean false
; storeboolean false
toa
; (noteArrayList
is not a descendant ofMap
)
Equality Equals
editUse the equality equals operator '=='
to COMPARE two values where a resultant
boolean
type value is true
if the two values are equal and false
otherwise. The member method, equals
, is implicitly called when the values are
reference type values where the first value is the target of the call and the
second value is the argument. This operation is null-safe where if both values
are null
the resultant boolean
type value is true
, and if only one value
is null
the resultant boolean
type value is false
. A valid comparison is
between boolean
type values, numeric type values, or reference type values.
Errors
-
If a comparison is made between a
boolean
type value and numeric type value. - If a comparison is made between a primitive type value and a reference type value.
Grammar
equality_equals: expression '==' expression;
Promotion
boolean |
byte |
short |
char |
int |
long |
float |
double |
Reference |
def |
|
boolean |
boolean |
- |
- |
- |
- |
- |
- |
- |
- |
def |
byte |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
short |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
char |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
int |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
long |
- |
long |
long |
long |
long |
long |
float |
double |
- |
def |
float |
- |
float |
float |
float |
float |
float |
float |
double |
- |
def |
double |
- |
double |
double |
double |
double |
double |
double |
double |
- |
def |
Reference |
- |
- |
- |
- |
- |
- |
- |
- |
Object |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Equality equals with the
boolean
type.declare
boolean a
; storeboolean true
toa
declare
boolean b
; storeboolean false
tob
load from
a
→boolean true
; equality equalsboolean true
andboolean false
→boolean false
; storeboolean false
toa
load from
a
→boolean false @0
; load fromb
→boolean false @1
; equality equalsboolean false @0
andboolean false @1
→boolean false
; storeboolean false
tob
-
Equality equals with primitive types.
declare
int a
; storeint 1
toa
declare
double b
; storedouble 1.0
tob
declare
boolean c
; load froma
→int 1
; load fromb
→double 2.0
; promoteint 1
anddouble 2.0
: resultdouble
; implicit castint 1
todouble 1.0
→double `1.0
; equality equalsdouble 1.0
anddouble 2.0
→boolean false
; storeboolean false
toc
load from
a
→int 1 @1
; equality equalsint 1 @0
andint 1 @1
→boolean true
; storeboolean true
toc
-
Equal equals with reference types.
List a = new ArrayList(); List b = new ArrayList(); a.add(1); boolean c = a == b; b.add(1); c = a == b;
declare
List a
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
toa
declare
List b
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
tob
load from
a
→List reference
; calladd
onList reference
with arguments (int 1)
declare
boolean c
; load froma
→List reference @0
; load fromb
→List reference @1
; callequals
onList reference @0
with arguments (List reference @1
) →boolean false
; storeboolean false
toc
load from
b
→List reference
; calladd
onList reference
with arguments (int 1
)load from
a
→List reference @0
; load fromb
→List reference @1
; callequals
onList reference @0
with arguments (List reference @1
) →boolean true
; storeboolean true
toc
-
Equality equals with
null
.declare
Object a
; storenull
toa
declare
Object b
; storenull
tob
declare
boolean c
; load froma
→null @0
; equality equalsnull @0
andnull @1
→boolean true
; storeboolean true
toc
load from
a
→null @0
; load fromb
→null @1
; equality equalsnull @0
andnull @1
→boolean true
; storeboolean true
toc
allocate
Object
instance →Object reference
; storeObject reference
tob
load from
a
→Object reference
; load fromb
→null
; callequals
onObject reference
with arguments (null
) →boolean false
; storeboolean false
toc
-
Equality equals with the
def
type.def a = 0; def b = 1; boolean c = a == b; def d = new HashMap(); def e = new ArrayList(); c = d == e;
declare
def a
; implicit castint 0
todef
→def
; storedef
toa
;declare
def b
; implicit castint 1
todef
→def
; storedef
tob
;declare
boolean c
; load froma
→def
; implicit casta
toint 0
→int 0
; load fromb
→def
; implicit castb
toint 1
→int 1
; equality equalsint 0
andint 1
→boolean false
; storeboolean false
toc
declare
def d
; allocateHashMap
instance →HashMap reference
; implicit castHashMap reference
todef
→def
storedef
tod
;declare
def e
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
todef
→def
storedef
tod
;load from
d
→def
; implicit castdef
toHashMap reference
→HashMap reference
; load frome
→def
; implicit castdef
toArrayList reference
→ArrayList reference
; callequals
onHashMap reference
with arguments (ArrayList reference
) →boolean false
; storeboolean false
toc
Equality Not Equals
editUse the equality not equals operator '!='
to COMPARE two values where a
resultant boolean
type value is true
if the two values are NOT equal and
false
otherwise. The member method, equals
, is implicitly called when the
values are reference type values where the first value is the target of the call
and the second value is the argument with the resultant boolean
type value
flipped. This operation is null-safe
where if both values are null
the
resultant boolean
type value is false
, and if only one value is null
the
resultant boolean
type value is true
. A valid comparison is between boolean
type values, numeric type values, or reference type values.
Errors
-
If a comparison is made between a
boolean
type value and numeric type value. - If a comparison is made between a primitive type value and a reference type value.
Grammar
equality_not_equals: expression '!=' expression;
Promotion
boolean |
byte |
short |
char |
int |
long |
float |
double |
Reference |
def |
|
boolean |
boolean |
- |
- |
- |
- |
- |
- |
- |
- |
def |
byte |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
short |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
char |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
int |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
long |
- |
long |
long |
long |
long |
long |
float |
double |
- |
def |
float |
- |
float |
float |
float |
float |
float |
float |
double |
- |
def |
double |
- |
double |
double |
double |
double |
double |
double |
double |
- |
def |
Reference |
- |
- |
- |
- |
- |
- |
- |
- |
Object |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Equality not equals with the
boolean
type.declare
boolean a
; storeboolean true
toa
declare
boolean b
; storeboolean false
tob
load from
a
→boolean true
; equality not equalsboolean true
andboolean false
→boolean true
; storeboolean true
toa
load from
a
→boolean true
; load fromb
→boolean false
; equality not equalsboolean true
andboolean false
→boolean true
; storeboolean true
tob
-
Equality not equals with primitive types.
declare
int a
; storeint 1
toa
declare
double b
; storedouble 1.0
tob
declare
boolean c
; load froma
→int 1
; load fromb
→double 2.0
; promoteint 1
anddouble 2.0
: resultdouble
; implicit castint 1
todouble 1.0
→double `1.0
; equality not equalsdouble 1.0
anddouble 2.0
→boolean true
; storeboolean true
toc
load from
a
→int 1 @1
; equality not equalsint 1 @0
andint 1 @1
→boolean false
; storeboolean false
toc
-
Equality not equals with reference types.
List a = new ArrayList(); List b = new ArrayList(); a.add(1); boolean c = a == b; b.add(1); c = a == b;
declare
List a
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
toa
declare
List b
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
tob
load from
a
→List reference
; calladd
onList reference
with arguments (int 1)
declare
boolean c
; load froma
→List reference @0
; load fromb
→List reference @1
; callequals
onList reference @0
with arguments (List reference @1
) →boolean false
; boolean notboolean false
→boolean true
storeboolean true
toc
load from
b
→List reference
; calladd
onList reference
with arguments (int 1
)load from
a
→List reference @0
; load fromb
→List reference @1
; callequals
onList reference @0
with arguments (List reference @1
) →boolean true
; boolean notboolean true
→boolean false
; storeboolean false
toc
-
Equality not equals with
null
.declare
Object a
; storenull
toa
declare
Object b
; storenull
tob
declare
boolean c
; load froma
→null @0
; equality not equalsnull @0
andnull @1
→boolean false
; storeboolean false
toc
load from
a
→null @0
; load fromb
→null @1
; equality not equalsnull @0
andnull @1
→boolean false
; storeboolean false
toc
allocate
Object
instance →Object reference
; storeObject reference
tob
load from
a
→Object reference
; load fromb
→null
; callequals
onObject reference
with arguments (null
) →boolean false
; boolean notboolean false
→boolean true
; storeboolean true
toc
-
Equality not equals with the
def
type.def a = 0; def b = 1; boolean c = a == b; def d = new HashMap(); def e = new ArrayList(); c = d == e;
declare
def a
; implicit castint 0
todef
→def
; storedef
toa
;declare
def b
; implicit castint 1
todef
→def
; storedef
tob
;declare
boolean c
; load froma
→def
; implicit casta
toint 0
→int 0
; load fromb
→def
; implicit castb
toint 1
→int 1
; equality equalsint 0
andint 1
→boolean false
; storeboolean false
toc
declare
def d
; allocateHashMap
instance →HashMap reference
; implicit castHashMap reference
todef
→def
storedef
tod
;declare
def e
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
todef
→def
storedef
tod
;load from
d
→def
; implicit castdef
toHashMap reference
→HashMap reference
; load frome
→def
; implicit castdef
toArrayList reference
→ArrayList reference
; callequals
onHashMap reference
with arguments (ArrayList reference
) →boolean false
; storeboolean false
toc
Identity Equals
editUse the identity equals operator '==='
to COMPARE two values where a resultant
boolean
type value is true
if the two values are equal and false
otherwise. A reference type value is equal to another reference type value if
both values refer to same instance on the heap or if both values are null
. A
valid comparison is between boolean
type values, numeric type values, or
reference type values.
Errors
-
If a comparison is made between a
boolean
type value and numeric type value. - If a comparison is made between a primitive type value and a reference type value.
Grammar
identity_equals: expression '===' expression;
Promotion
boolean |
byte |
short |
char |
int |
long |
float |
double |
Reference |
def |
|
boolean |
boolean |
- |
- |
- |
- |
- |
- |
- |
- |
def |
byte |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
short |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
char |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
int |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
long |
- |
long |
long |
long |
long |
long |
float |
double |
- |
def |
float |
- |
float |
float |
float |
float |
float |
float |
double |
- |
def |
double |
- |
double |
double |
double |
double |
double |
double |
double |
- |
def |
Reference |
- |
- |
- |
- |
- |
- |
- |
- |
Object |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Identity equals with reference types.
declare
List a
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
toa
declare
List b
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
tob
load from
a
→List reference
; storeList reference
toc
declare
boolean c
; load froma
→List reference @0
; load fromb
→List reference @1
; identity equalsList reference @0
andList reference @1
→boolean false
storeboolean false
toc
load from
a
→List reference @0
; load fromc
→List reference @1
; identity equalsList reference @0
andList reference @1
→boolean true
storeboolean true
toc
(noteList reference @0
andList reference @1
refer to the same instance) -
Identity equals with
null
.Object a = null; Object b = null; boolean c = a === null; c = a === b; b = new Object(); c = a === b;
declare
Object a
; storenull
toa
declare
Object b
; storenull
tob
declare
boolean c
; load froma
→null @0
; identity equalsnull @0
andnull @1
→boolean true
; storeboolean true
toc
load from
a
→null @0
; load fromb
→null @1
; identity equalsnull @0
andnull @1
→boolean true
; storeboolean true
toc
allocate
Object
instance →Object reference
; storeObject reference
tob
load from
a
→Object reference
; load fromb
→null
; identity equalsObject reference
andnull
→boolean false
; storeboolean false
toc
-
Identity equals with the
def
type.declare
def d
; allocateHashMap
instance →HashMap reference
; implicit castHashMap reference
todef
→def
storedef
tod
declare
def e
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
todef
→def
storedef
tod
declare
boolean c
; load froma
→def
; implicit castdef
toHashMap reference
→HashMap reference
; load fromb
→def
; implicit castdef
toArrayList reference
→ArrayList reference
; identity equalsHashMap reference
andArrayList reference
→boolean false
; storeboolean false
toc
load from
a
→def
; storedef
tob
load from
a
→def
; implicit castdef
toHashMap reference @0
→HashMap reference @0
; load fromb
→def
; implicit castdef
toHashMap reference @1
→HashMap reference @1
; identity equalsHashMap reference @0
andHashMap reference @1
→boolean true
; storeboolean true
tob
; (noteHashMap reference @0
andHashMap reference @1
refer to the same instance)
Identity Not Equals
editUse the identity not equals operator '!=='
to COMPARE two values where a
resultant boolean
type value is true
if the two values are NOT equal and
false
otherwise. A reference type value is not equal to another reference type
value if both values refer to different instances on the heap or if one value is
null
and the other is not. A valid comparison is between boolean
type
values, numeric type values, or reference type values.
Errors
-
If a comparison is made between a
boolean
type value and numeric type value. - If a comparison is made between a primitive type value and a reference type value.
Grammar
identity_not_equals: expression '!==' expression;
Promotion
boolean |
byte |
short |
char |
int |
long |
float |
double |
Reference |
def |
|
boolean |
boolean |
- |
- |
- |
- |
- |
- |
- |
- |
def |
byte |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
short |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
char |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
int |
- |
int |
int |
int |
int |
long |
float |
double |
- |
def |
long |
- |
long |
long |
long |
long |
long |
float |
double |
- |
def |
float |
- |
float |
float |
float |
float |
float |
float |
double |
- |
def |
double |
- |
double |
double |
double |
double |
double |
double |
double |
- |
def |
Reference |
- |
- |
- |
- |
- |
- |
- |
- |
Object |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Identity not equals with reference type values.
declare
List a
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
toa
declare
List b
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
toList reference
→List reference
; storeList reference
tob
load from
a
→List reference
; storeList reference
toc
declare
boolean c
; load froma
→List reference @0
; load fromb
→List reference @1
; identity not equalsList reference @0
andList reference @1
→boolean true
storeboolean true
toc
load from
a
→List reference @0
; load fromc
→List reference @1
; identity not equalsList reference @0
andList reference @1
→boolean false
storeboolean false
toc
(noteList reference @0
andList reference @1
refer to the same instance) -
Identity not equals with
null
.Object a = null; Object b = null; boolean c = a !== null; c = a !== b; b = new Object(); c = a !== b;
declare
Object a
; storenull
toa
declare
Object b
; storenull
tob
declare
boolean c
; load froma
→null @0
; identity not equalsnull @0
andnull @1
→boolean false
; storeboolean false
toc
load from
a
→null @0
; load fromb
→null @1
; identity not equalsnull @0
andnull @1
→boolean false
; storeboolean false
toc
allocate
Object
instance →Object reference
; storeObject reference
tob
load from
a
→Object reference
; load fromb
→null
; identity not equalsObject reference
andnull
→boolean true
; storeboolean true
toc
-
Identity not equals with the
def
type.declare
def d
; allocateHashMap
instance →HashMap reference
; implicit castHashMap reference
todef
→def
storedef
tod
declare
def e
; allocateArrayList
instance →ArrayList reference
; implicit castArrayList reference
todef
→def
storedef
tod
declare
boolean c
; load froma
→def
; implicit castdef
toHashMap reference
→HashMap reference
; load fromb
→def
; implicit castdef
toArrayList reference
→ArrayList reference
; identity not equalsHashMap reference
andArrayList reference
→boolean true
; storeboolean true
toc
load from
a
→def
; storedef
tob
load from
a
→def
; implicit castdef
toHashMap reference @0
→HashMap reference @0
; load fromb
→def
; implicit castdef
toHashMap reference @1
→HashMap reference @1
; identity not equalsHashMap reference @0
andHashMap reference @1
→boolean false
; storeboolean false
tob
; (noteHashMap reference @0
andHashMap reference @1
refer to the same instance)
Boolean Xor
editUse the boolean xor operator '^'
to XOR together two boolean
type values
where if one boolean
type value is true
and the other is false
the
resultant boolean
type value is true
and false
otherwise.
Errors
-
If either evaluated value is a value other than a
boolean
type value or a value that is castable to aboolean
type value.
Truth
true |
false |
|
true |
false |
true |
false |
true |
false |
Grammar
boolean_xor: expression '^' expression;
Examples
-
Boolean xor with the
boolean
type.declare
boolean x
; storeboolean false
tox
declare
boolean y
; load fromx
→boolean false
boolean xorboolean false
andboolean true
→boolean true
; storeboolean true
toy
load from
y
→boolean true @0
; load fromx
→boolean true @1
; boolean xorboolean true @0
andboolean true @1
→boolean false
; storeboolean false
toy
-
Boolean xor with the
def
type.declare
def x
; implicit castboolean false
todef
→def
; storedef
tox
declare
def y
; load fromx
→def
; implicit castdef
toboolean false
→boolean false
; boolean xorboolean false
andboolean true
→boolean true
; implicit castboolean true
todef
→def
; storedef
toy
load from
y
→def
; implicit castdef
toboolean true @0
→boolean true @0
; load fromx
→def
; implicit castdef
toboolean true @1
→boolean true @1
; boolean xorboolean true @0
andboolean true @1
→boolean false
; implicit castboolean false
→def
; storedef
toy
Boolean And
editUse the boolean and operator '&&'
to AND together two boolean
type values
where if both boolean
type values are true
the resultant boolean
type
value is true
and false
otherwise.
Errors
-
If either evaluated value is a value other than a
boolean
type value or a value that is castable to aboolean
type value.
Truth
true |
false |
|
true |
true |
false |
false |
false |
false |
Grammar
boolean_and: expression '&&' expression;
Examples
-
Boolean and with the
boolean
type.declare
boolean x
; storeboolean true
tox
declare
boolean y
; load fromx
→boolean true @0
; boolean andboolean true @0
andboolean true @1
→boolean true
; storeboolean true
toy
store
boolean false
tox
load from
y
→boolean true
; load fromx
→boolean false
; boolean andboolean true
andboolean false
→boolean false
; storeboolean false
toy
-
Boolean and with the
def
type.declare
def x
; implicit castboolean true
todef
→def
; storedef
tox
declare
def y
; load fromx
→def
; implicit castdef
toboolean true @0
→boolean true @0
; boolean andboolean true @0
andboolean true @1
→boolean true
; implicit castboolean true
todef
→def
; storedef
toy
implicit cast
boolean false
todef
→def
; storedef
tox
;load from
y
→def
; implicit castdef
toboolean true
→boolean true
; load fromx
→def
; implicit castdef
toboolean false
→boolean false
; boolean andboolean true
andboolean false
→boolean false
; implicit castboolean false
→def
; storedef
toy
Boolean Or
editUse the boolean or operator '||'
to OR together two boolean
type values
where if either one of the boolean
type values is true
the resultant
boolean
type value is true
and false
otherwise.
Errors
-
If either evaluated value is a value other than a
boolean
type value or a value that is castable to aboolean
type value.
Truth
true |
false |
|
true |
true |
true |
false |
true |
false |
Grammar:
boolean_and: expression '||' expression;
Examples
-
Boolean or with the
boolean
type.declare
boolean x
; storeboolean false
tox
declare
boolean y
; load fromx
→boolean false
; boolean orboolean false
andboolean true
→boolean true
; storeboolean true
toy
store
boolean false
toy
load from
y
→boolean false @0
; load fromx
→boolean false @1
; boolean orboolean false @0
andboolean false @1
→boolean false
; storeboolean false
toy
-
Boolean or with the
def
type.declare
def x
; implicit castboolean false
todef
→def
; storedef
tox
declare
def y
; load fromx
→def
; implicit castdef
toboolean false
→boolean true
; boolean orboolean false
andboolean true
→boolean true
; implicit castboolean true
todef
→def
; storedef
toy
implicit cast
boolean false
todef
→def
; storedef
toy
;load from
y
→def
; implicit castdef
toboolean false @0
→boolean false @0
; load fromx
→def
; implicit castdef
toboolean false @1
→boolean false @1
; boolean orboolean false @0
andboolean false @1
→boolean false
; implicit castboolean false
→def
; storedef
toy