Operators: Boolean
Use 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 x = !false; 1 boolean y = !x; 2
- declare
boolean x
; boolean notboolean false
→boolean true
; storeboolean true
tox
- declare
boolean y
; load fromx
→boolean true
; boolean notboolean true
→boolean false
; storeboolean false
toy
- declare
Boolean not with the
def
type.def y = true; 1 def z = !y; 2
- declare
def y
; implicit castboolean true
todef
→def
; storetrue
toy
- declare
def z
; load fromy
→def
; implicit castdef
toboolean true
→ booleantrue
; boolean notboolean true
→boolean false
; implicit castboolean false
todef
→def
; storedef
toz
- declare
Use 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.
boolean x = 5 > 4; 1 double y = 6.0; 2 x = 6 > y; 3
- 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
- declare
Greater than with
def
type.int x = 5; 1 def y = 7.0; 2 def z = y > 6.5; 3 def a = x > y; 4
- 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
- declare
Use 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.
boolean x = 5 >= 4; 1 double y = 6.0; 2 x = 6 >= y; 3
- 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
- declare
Greater than or equal with the
def
type.int x = 5; 1 def y = 7.0; 2 def z = y >= 7.0; 3 def a = x >= y; 4
- 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
- declare
Use 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.
boolean x = 5 < 4; 1 double y = 6.0; 2 x = 6 < y; 3
- 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
- declare
Less than with the
def
type.int x = 5; 1 def y = 7.0; 2 def z = y < 6.5; 3 def a = x < y; 4
- 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
- declare
Use 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.
boolean x = 5 <= 4; 1 double y = 6.0; 2 x = 6 <= y; 3
- 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
- declare
Less than or equal with the
def
type.int x = 5; 1 def y = 7.0; 2 def z = y <= 7.0; 3 def a = x <= y; 4
- 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
- declare
Use 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.
Map m = new HashMap(); 1 boolean a = m instanceof HashMap; 2 boolean b = m instanceof Map; 3
- 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
)
- declare
Instance of with the
def
type.def d = new ArrayList(); 1 boolean a = d instanceof List; 2 boolean b = d instanceof Map; 3
- 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
)
- declare
Use 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.boolean a = true; 1 boolean b = false; 2 a = a == false; 3 b = a == b; 4
- 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
- declare
Equality equals with primitive types.
int a = 1; 1 double b = 2.0; 2 boolean c = a == b; 3 c = 1 == a; 4
- 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 equals
double 1.0and
double 2.0→
boolean false; store
boolean falseto
c` - load from
a
→int 1 @1
; equality equalsint 1 @0
andint 1 @1
→boolean true
; storeboolean true
toc
- declare
Equal equals with reference types.
List a = new ArrayList(); 1 List b = new ArrayList(); 2 a.add(1); 3 boolean c = a == b; 4 b.add(1); 5 c = a == b; 6
- 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
- declare
Equality equals with
null
.Object a = null; 1 Object b = null; 2 boolean c = a == null; 3 c = a == b; 4 b = new Object(); 5 c = a == b; 6
- 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
- declare
Equality equals with the
def
type.def a = 0; 1 def b = 1; 2 boolean c = a == b; 3 def d = new HashMap(); 4 def e = new ArrayList(); 5 c = d == e; 6
- 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
- declare
Use 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.boolean a = true; 1 boolean b = false; 2 a = a != false; 3 b = a != b; 4
- 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
- declare
Equality not equals with primitive types.
int a = 1; 1 double b = 2.0; 2 boolean c = a != b; 3 c = 1 != a; 4
- 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 equals
double 1.0and
double 2.0→
boolean true; store
boolean trueto
c` - load from
a
→int 1 @1
; equality not equalsint 1 @0
andint 1 @1
→boolean false
; storeboolean false
toc
- declare
Equality not equals with reference types.
List a = new ArrayList(); 1 List b = new ArrayList(); 2 a.add(1); 3 boolean c = a == b; 4 b.add(1); 5 c = a == b; 6
- 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
- declare
Equality not equals with
null
.Object a = null; 1 Object b = null; 2 boolean c = a == null; 3 c = a == b; 4 b = new Object(); 5 c = a == b; 6
- 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
- declare
Equality not equals with the
def
type.def a = 0; 1 def b = 1; 2 boolean c = a == b; 3 def d = new HashMap(); 4 def e = new ArrayList(); 5 c = d == e; 6
- 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
- declare
Use 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.
List a = new ArrayList(); 1 List b = new ArrayList(); 2 List c = a; 3 boolean c = a === b; 4 c = a === c; 5
- 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)
- declare
Identity equals with
null
.Object a = null; 1 Object b = null; 2 boolean c = a === null; 3 c = a === b; 4 b = new Object(); 5 c = a === b; 6
- 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
- declare
Identity equals with the
def
type.def a = new HashMap(); 1 def b = new ArrayList(); 2 boolean c = a === b; 3 b = a; 4 c = a === b; 5
- 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)
- declare
Use 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.
List a = new ArrayList(); 1 List b = new ArrayList(); 2 List c = a; 3 boolean c = a !== b; 4 c = a !== c; 5
- 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)
- declare
Identity not equals with
null
.Object a = null; 1 Object b = null; 2 boolean c = a !== null; 3 c = a !== b; 4 b = new Object(); 5 c = a !== b; 6
- 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
- declare
Identity not equals with the
def
type.def a = new HashMap(); 1 def b = new ArrayList(); 2 boolean c = a !== b; 3 b = a; 4 c = a !== b; 5
- 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)
- declare
Use 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.boolean x = false; 1 boolean y = x ^ true; 2 y = y ^ x; 3
- 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
- declare
Boolean xor with the
def
type.def x = false; 1 def y = x ^ true; 2 y = y ^ x; 3
- 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
- declare
Use 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.boolean x = true; 1 boolean y = x && true; 2 x = false; 3 y = y && x; 4
- 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
- declare
Boolean and with the
def
type.def x = true; 1 def y = x && true; 2 x = false; 3 y = y && x; 4
- 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
- declare
Use 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.boolean x = false; 1 boolean y = x || true; 2 y = false; 3 y = y || x; 4
- 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
- declare
Boolean or with the
def
type.def x = false; 1 def y = x || true; 2 y = false; 3 y = y || x; 4
- 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
- declare