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
booleantype value or a value that is castable to abooleantype value is given.
Truth
| original | result |
|---|---|
true |
false |
false |
true |
Grammar
boolean_not: '!' expression;
Examples
-
Boolean not with the
booleantype. -
Boolean not with the
deftype.
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 5andint 4→boolean true; storeboolean truetox;declare
double y; storedouble 6.0toy;load from
y→double 6.0 @0; promoteint 6anddouble 6.0: resultdouble; implicit castint 6todouble 6.0 @1→double 6.0 @1; greater thandouble 6.0 @1anddouble 6.0 @0→boolean false; storeboolean falsetox -
Greater than with
deftype.declare
int x; storeint 5toxdeclare
def y; implicit castdouble 7.0todef→def; storedeftoydeclare
def z; load fromy→def; implicit castdeftodouble 7.0→double 7.0; greater thandouble 7.0anddouble 6.5→boolean true; implicit castboolean truetodef→def; storedeftozdeclare
def a; load fromy→def; implicit castdeftodouble 7.0→double 7.0; load fromx→int 5; promoteint 5anddouble 7.0: resultdouble; implicit castint 5todouble 5.0→double 5.0; greater thandouble 5.0anddouble 7.0→boolean false; implicit castboolean falsetodef→def; storedeftoz
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 5andint 4→boolean true; storeboolean truetoxdeclare
double y; storedouble 6.0toyload from
y→double 6.0 @0; promoteint 6anddouble 6.0: resultdouble; implicit castint 6todouble 6.0 @1→double 6.0 @1; greater than or equaldouble 6.0 @1anddouble 6.0 @0→boolean true; storeboolean truetox -
Greater than or equal with the
deftype.declare
int x; storeint 5tox;declare
def yimplicit castdouble 7.0todef→def; storedeftoydeclare
def z; load fromy→def; implicit castdeftodouble 7.0 @0→double 7.0 @0; greater than or equaldouble 7.0 @0anddouble 7.0 @1→boolean true; implicit castboolean truetodef→def; storedeftozdeclare
def a; load fromy→def; implicit castdeftodouble 7.0→double 7.0; load fromx→int 5; promoteint 5anddouble 7.0: resultdouble; implicit castint 5todouble 5.0→double 5.0; greater than or equaldouble 5.0anddouble 7.0→boolean false; implicit castboolean falsetodef→def; storedeftoz
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 5andint 4→boolean false; storeboolean falsetoxdeclare
double y; storedouble 6.0toyload from
y→double 6.0 @0; promoteint 6anddouble 6.0: resultdouble; implicit castint 6todouble 6.0 @1→double 6.0 @1; less thandouble 6.0 @1anddouble 6.0 @0→boolean false; storeboolean falsetox -
Less than with the
deftype.declare
int x; storeint 5toxdeclare
def y; implicit castdouble 7.0todef→def; storedeftoydeclare
def z; load fromy→def; implicit castdeftodouble 7.0→double 7.0; less thandouble 7.0anddouble 6.5→boolean false; implicit castboolean falsetodef→def; storedeftozdeclare
def a; load fromy→def; implicit castdeftodouble 7.0→double 7.0; load fromx→int 5; promoteint 5anddouble 7.0: resultdouble; implicit castint 5todouble 5.0→double 5.0; less thandouble 5.0anddouble 7.0→boolean true; implicit castboolean truetodef→def; storedeftoz
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 5andint 4→boolean false; storeboolean truetoxdeclare
double y; storedouble 6.0toyload from
y→double 6.0 @0; promoteint 6anddouble 6.0: resultdouble; implicit castint 6todouble 6.0 @1→double 6.0 @1; less than or equaldouble 6.0 @1anddouble 6.0 @0→boolean true; storeboolean truetox -
Less than or equal with the
deftype.declare
int x; storeint 5tox;declare
def y; implicit castdouble 7.0todef→def; storedeftoy;declare
def z; load fromy→def; implicit castdeftodouble 7.0 @0→double 7.0 @0; less than or equaldouble 7.0 @0anddouble 7.0 @1→boolean true; implicit castboolean truetodef→def; storedeftozdeclare
def a; load fromy→def; implicit castdeftodouble 7.0→double 7.0; load fromx→int 5; promoteint 5anddouble 7.0: resultdouble; implicit castint 5todouble 5.0→double 5.0; less than or equaldouble 5.0anddouble 7.0→boolean true; implicit castboolean truetodef→def; storedeftoz
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; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetoMap reference; storeMap referencetomdeclare
boolean a; load fromm→Map reference; implicit castMap referencetoHashMap reference→HashMap reference; instanceofHashMap referenceandHashMap→boolean true; storeboolean truetoadeclare
boolean b; load fromm→Map reference; implicit castMap referencetoHashMap reference→HashMap reference; instanceofHashMap referenceandMap→boolean true; storetruetob; (noteHashMapis a descendant ofMap) -
Instance of with the
deftype.declare
def d; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→def; storedeftoddeclare
boolean a; load fromd→def; implicit castdeftoArrayList reference→ArrayList reference; instanceofArrayList referenceandList→boolean true; storeboolean truetoa; (noteArrayListis a descendant ofList)declare
boolean b; load fromd→def; implicit castdeftoArrayList reference→ArrayList reference; instanceofArrayList referenceandMap→boolean false; storeboolean falsetoa; (noteArrayListis 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
booleantype 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
booleantype.declare
boolean a; storeboolean truetoadeclare
boolean b; storeboolean falsetobload from
a→boolean true; equality equalsboolean trueandboolean false→boolean false; storeboolean falsetoaload from
a→boolean false @0; load fromb→boolean false @1; equality equalsboolean false @0andboolean false @1→boolean false; storeboolean falsetob -
Equality equals with primitive types.
declare
int a; storeint 1toadeclare
double b; storedouble 1.0tobdeclare
boolean c; load froma→int 1; load fromb→double 2.0; promoteint 1anddouble 2.0: resultdouble; implicit castint 1todouble 1.0→double `1.0; equality equalsdouble 1.0anddouble 2.0→boolean false; storeboolean falsetocload from
a→int 1 @1; equality equalsint 1 @0andint 1 @1→boolean true; storeboolean truetoc -
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; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetoadeclare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetobload from
a→List reference; calladdonList referencewith arguments (int 1)declare
boolean c; load froma→List reference @0; load fromb→List reference @1; callequalsonList reference @0with arguments (List reference @1) →boolean false; storeboolean falsetocload from
b→List reference; calladdonList referencewith arguments (int 1)load from
a→List reference @0; load fromb→List reference @1; callequalsonList reference @0with arguments (List reference @1) →boolean true; storeboolean truetoc -
Equality equals with
null.declare
Object a; storenulltoadeclare
Object b; storenulltobdeclare
boolean c; load froma→null @0; equality equalsnull @0andnull @1→boolean true; storeboolean truetocload from
a→null @0; load fromb→null @1; equality equalsnull @0andnull @1→boolean true; storeboolean truetocallocate
Objectinstance →Object reference; storeObject referencetobload from
a→Object reference; load fromb→null; callequalsonObject referencewith arguments (null) →boolean false; storeboolean falsetoc -
Equality equals with the
deftype.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 0todef→def; storedeftoa;declare
def b; implicit castint 1todef→def; storedeftob;declare
boolean c; load froma→def; implicit castatoint 0→int 0; load fromb→def; implicit castbtoint 1→int 1; equality equalsint 0andint 1→boolean false; storeboolean falsetocdeclare
def d; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetodef→defstoredeftod;declare
def e; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→defstoredeftod;load from
d→def; implicit castdeftoHashMap reference→HashMap reference; load frome→def; implicit castdeftoArrayList reference→ArrayList reference; callequalsonHashMap referencewith arguments (ArrayList reference) →boolean false; storeboolean falsetoc
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
booleantype 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
booleantype.declare
boolean a; storeboolean truetoadeclare
boolean b; storeboolean falsetobload from
a→boolean true; equality not equalsboolean trueandboolean false→boolean true; storeboolean truetoaload from
a→boolean true; load fromb→boolean false; equality not equalsboolean trueandboolean false→boolean true; storeboolean truetob -
Equality not equals with primitive types.
declare
int a; storeint 1toadeclare
double b; storedouble 1.0tobdeclare
boolean c; load froma→int 1; load fromb→double 2.0; promoteint 1anddouble 2.0: resultdouble; implicit castint 1todouble 1.0→double `1.0; equality not equalsdouble 1.0anddouble 2.0→boolean true; storeboolean truetocload from
a→int 1 @1; equality not equalsint 1 @0andint 1 @1→boolean false; storeboolean falsetoc -
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; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetoadeclare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetobload from
a→List reference; calladdonList referencewith arguments (int 1)declare
boolean c; load froma→List reference @0; load fromb→List reference @1; callequalsonList reference @0with arguments (List reference @1) →boolean false; boolean notboolean false→boolean truestoreboolean truetocload from
b→List reference; calladdonList referencewith arguments (int 1)load from
a→List reference @0; load fromb→List reference @1; callequalsonList reference @0with arguments (List reference @1) →boolean true; boolean notboolean true→boolean false; storeboolean falsetoc -
Equality not equals with
null.declare
Object a; storenulltoadeclare
Object b; storenulltobdeclare
boolean c; load froma→null @0; equality not equalsnull @0andnull @1→boolean false; storeboolean falsetocload from
a→null @0; load fromb→null @1; equality not equalsnull @0andnull @1→boolean false; storeboolean falsetocallocate
Objectinstance →Object reference; storeObject referencetobload from
a→Object reference; load fromb→null; callequalsonObject referencewith arguments (null) →boolean false; boolean notboolean false→boolean true; storeboolean truetoc -
Equality not equals with the
deftype.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 0todef→def; storedeftoa;declare
def b; implicit castint 1todef→def; storedeftob;declare
boolean c; load froma→def; implicit castatoint 0→int 0; load fromb→def; implicit castbtoint 1→int 1; equality equalsint 0andint 1→boolean false; storeboolean falsetocdeclare
def d; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetodef→defstoredeftod;declare
def e; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→defstoredeftod;load from
d→def; implicit castdeftoHashMap reference→HashMap reference; load frome→def; implicit castdeftoArrayList reference→ArrayList reference; callequalsonHashMap referencewith arguments (ArrayList reference) →boolean false; storeboolean falsetoc
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
booleantype 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; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetoadeclare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetobload from
a→List reference; storeList referencetocdeclare
boolean c; load froma→List reference @0; load fromb→List reference @1; identity equalsList reference @0andList reference @1→boolean falsestoreboolean falsetocload from
a→List reference @0; load fromc→List reference @1; identity equalsList reference @0andList reference @1→boolean truestoreboolean truetoc(noteList reference @0andList reference @1refer 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; storenulltoadeclare
Object b; storenulltobdeclare
boolean c; load froma→null @0; identity equalsnull @0andnull @1→boolean true; storeboolean truetocload from
a→null @0; load fromb→null @1; identity equalsnull @0andnull @1→boolean true; storeboolean truetocallocate
Objectinstance →Object reference; storeObject referencetobload from
a→Object reference; load fromb→null; identity equalsObject referenceandnull→boolean false; storeboolean falsetoc -
Identity equals with the
deftype.declare
def d; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetodef→defstoredeftoddeclare
def e; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→defstoredeftoddeclare
boolean c; load froma→def; implicit castdeftoHashMap reference→HashMap reference; load fromb→def; implicit castdeftoArrayList reference→ArrayList reference; identity equalsHashMap referenceandArrayList reference→boolean false; storeboolean falsetocload from
a→def; storedeftobload from
a→def; implicit castdeftoHashMap reference @0→HashMap reference @0; load fromb→def; implicit castdeftoHashMap reference @1→HashMap reference @1; identity equalsHashMap reference @0andHashMap reference @1→boolean true; storeboolean truetob; (noteHashMap reference @0andHashMap reference @1refer 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
booleantype 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; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetoadeclare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetobload from
a→List reference; storeList referencetocdeclare
boolean c; load froma→List reference @0; load fromb→List reference @1; identity not equalsList reference @0andList reference @1→boolean truestoreboolean truetocload from
a→List reference @0; load fromc→List reference @1; identity not equalsList reference @0andList reference @1→boolean falsestoreboolean falsetoc(noteList reference @0andList reference @1refer 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; storenulltoadeclare
Object b; storenulltobdeclare
boolean c; load froma→null @0; identity not equalsnull @0andnull @1→boolean false; storeboolean falsetocload from
a→null @0; load fromb→null @1; identity not equalsnull @0andnull @1→boolean false; storeboolean falsetocallocate
Objectinstance →Object reference; storeObject referencetobload from
a→Object reference; load fromb→null; identity not equalsObject referenceandnull→boolean true; storeboolean truetoc -
Identity not equals with the
deftype.declare
def d; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetodef→defstoredeftoddeclare
def e; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→defstoredeftoddeclare
boolean c; load froma→def; implicit castdeftoHashMap reference→HashMap reference; load fromb→def; implicit castdeftoArrayList reference→ArrayList reference; identity not equalsHashMap referenceandArrayList reference→boolean true; storeboolean truetocload from
a→def; storedeftobload from
a→def; implicit castdeftoHashMap reference @0→HashMap reference @0; load fromb→def; implicit castdeftoHashMap reference @1→HashMap reference @1; identity not equalsHashMap reference @0andHashMap reference @1→boolean false; storeboolean falsetob; (noteHashMap reference @0andHashMap reference @1refer 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
booleantype value or a value that is castable to abooleantype value.
Truth
true |
false |
|
true |
false |
true |
false |
true |
false |
Grammar
boolean_xor: expression '^' expression;
Examples
-
Boolean xor with the
booleantype.declare
boolean x; storeboolean falsetoxdeclare
boolean y; load fromx→boolean falseboolean xorboolean falseandboolean true→boolean true; storeboolean truetoyload from
y→boolean true @0; load fromx→boolean true @1; boolean xorboolean true @0andboolean true @1→boolean false; storeboolean falsetoy -
Boolean xor with the
deftype.declare
def x; implicit castboolean falsetodef→def; storedeftoxdeclare
def y; load fromx→def; implicit castdeftoboolean false→boolean false; boolean xorboolean falseandboolean true→boolean true; implicit castboolean truetodef→def; storedeftoyload from
y→def; implicit castdeftoboolean true @0→boolean true @0; load fromx→def; implicit castdeftoboolean true @1→boolean true @1; boolean xorboolean true @0andboolean true @1→boolean false; implicit castboolean false→def; storedeftoy
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
booleantype value or a value that is castable to abooleantype value.
Truth
true |
false |
|
true |
true |
false |
false |
false |
false |
Grammar
boolean_and: expression '&&' expression;
Examples
-
Boolean and with the
booleantype.declare
boolean x; storeboolean truetoxdeclare
boolean y; load fromx→boolean true @0; boolean andboolean true @0andboolean true @1→boolean true; storeboolean truetoystore
boolean falsetoxload from
y→boolean true; load fromx→boolean false; boolean andboolean trueandboolean false→boolean false; storeboolean falsetoy -
Boolean and with the
deftype.declare
def x; implicit castboolean truetodef→def; storedeftoxdeclare
def y; load fromx→def; implicit castdeftoboolean true @0→boolean true @0; boolean andboolean true @0andboolean true @1→boolean true; implicit castboolean truetodef→def; storedeftoyimplicit cast
boolean falsetodef→def; storedeftox;load from
y→def; implicit castdeftoboolean true→boolean true; load fromx→def; implicit castdeftoboolean false→boolean false; boolean andboolean trueandboolean false→boolean false; implicit castboolean false→def; storedeftoy
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
booleantype value or a value that is castable to abooleantype value.
Truth
true |
false |
|
true |
true |
true |
false |
true |
false |
Grammar:
boolean_and: expression '||' expression;
Examples
-
Boolean or with the
booleantype.declare
boolean x; storeboolean falsetoxdeclare
boolean y; load fromx→boolean false; boolean orboolean falseandboolean true→boolean true; storeboolean truetoystore
boolean falsetoyload from
y→boolean false @0; load fromx→boolean false @1; boolean orboolean false @0andboolean false @1→boolean false; storeboolean falsetoy -
Boolean or with the
deftype.declare
def x; implicit castboolean falsetodef→def; storedeftoxdeclare
def y; load fromx→def; implicit castdeftoboolean false→boolean true; boolean orboolean falseandboolean true→boolean true; implicit castboolean truetodef→def; storedeftoyimplicit cast
boolean falsetodef→def; storedeftoy;load from
y→def; implicit castdeftoboolean false @0→boolean false @0; load fromx→def; implicit castdeftoboolean false @1→boolean false @1; boolean orboolean false @0andboolean false @1→boolean false; implicit castboolean false→def; storedeftoy