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
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 x = !false; boolean y = !x;- declare
boolean x; boolean notboolean false→boolean true; storeboolean truetox - declare
boolean y; load fromx→boolean true; boolean notboolean true→boolean false; storeboolean falsetoy
- declare
Boolean not with the
deftype.def y = true; def z = !y;- declare
def y; implicit castboolean truetodef→def; storetruetoy - declare
def z; load fromy→def; implicit castdeftoboolean true→ booleantrue; boolean notboolean true→boolean false; implicit castboolean falsetodef→def; storedeftoz
- 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; double y = 6.0; x = 6 > y;- 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
- declare
Greater than with
deftype.int x = 5; def y = 7.0; def z = y > 6.5; def a = x > y;- declare
int x; storeint 5tox - declare
def y; implicit castdouble 7.0todef→def; storedeftoy - declare
def z; load fromy→def; implicit castdeftodouble 7.0→double 7.0; greater thandouble 7.0anddouble 6.5→boolean true; implicit castboolean truetodef→def; storedeftoz - declare
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
- 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; double y = 6.0; x = 6 >= y;- declare
boolean x; greater than or equalint 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 than or equaldouble 6.0 @1anddouble 6.0 @0→boolean true; storeboolean truetox
- declare
Greater than or equal with the
deftype.int x = 5; def y = 7.0; def z = y >= 7.0; def a = x >= y;- declare
int x; storeint 5tox; - declare
def yimplicit castdouble 7.0todef→def; storedeftoy - declare
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; storedeftoz - declare
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
- 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; double y = 6.0; x = 6 < y;- declare
boolean x; less thanint 5andint 4→boolean false; storeboolean falsetox - 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; less thandouble 6.0 @1anddouble 6.0 @0→boolean false; storeboolean falsetox
- declare
Less than with the
deftype.int x = 5; def y = 7.0; def z = y < 6.5; def a = x < y;- declare
int x; storeint 5tox - declare
def y; implicit castdouble 7.0todef→def; storedeftoy - declare
def z; load fromy→def; implicit castdeftodouble 7.0→double 7.0; less thandouble 7.0anddouble 6.5→boolean false; implicit castboolean falsetodef→def; storedeftoz - declare
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
- 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; double y = 6.0; x = 6 <= y;- declare
boolean x; less than or equalint 5andint 4→boolean false; 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; less than or equaldouble 6.0 @1anddouble 6.0 @0→boolean true; storeboolean truetox
- declare
Less than or equal with the
deftype.int x = 5; def y = 7.0; def z = y <= 7.0; def a = x <= y;- 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; storedeftoz - declare
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
- 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(); boolean a = m instanceof HashMap; boolean b = m instanceof Map;- declare
Map m; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetoMap reference; storeMap referencetom - declare
boolean a; load fromm→Map reference; implicit castMap referencetoHashMap reference→HashMap reference; instanceofHashMap referenceandHashMap→boolean true; storeboolean truetoa - declare
boolean b; load fromm→Map reference; implicit castMap referencetoHashMap reference→HashMap reference; instanceofHashMap referenceandMap→boolean true; storetruetob; (noteHashMapis a descendant ofMap)
- declare
Instance of with the
deftype.def d = new ArrayList(); boolean a = d instanceof List; boolean b = d instanceof Map;- declare
def d; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→def; storedeftod - declare
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)
- 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
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.boolean a = true; boolean b = false; a = a == false; b = a == b;- declare
boolean a; storeboolean truetoa - declare
boolean b; storeboolean falsetob - load from
a→boolean true; equality equalsboolean trueandboolean false→boolean false; storeboolean falsetoa - load from
a→boolean false @0; load fromb→boolean false @1; equality equalsboolean false @0andboolean false @1→boolean false; storeboolean falsetob
- declare
Equality equals with primitive types.
int a = 1; double b = 2.0; boolean c = a == b; c = 1 == a;- declare
int a; storeint 1toa - declare
double b; storedouble 1.0tob - declare
boolean c; load froma→int 1; load fromb→double 2.0; promoteint 1anddouble 2.0: resultdouble; implicit castint 1todouble 1.0→double1.0; equality equalsdouble 1.0anddouble 2.0→boolean false; storeboolean falsetoc` - load from
a→int 1 @1; equality equalsint 1 @0andint 1 @1→boolean true; storeboolean truetoc
- declare
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 referencetoa - declare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetob - load 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 falsetoc - load 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
- declare
Equality 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; storenulltoa - declare
Object b; storenulltob - declare
boolean c; load froma→null @0; equality equalsnull @0andnull @1→boolean true; storeboolean truetoc - load from
a→null @0; load fromb→null @1; equality equalsnull @0andnull @1→boolean true; storeboolean truetoc - allocate
Objectinstance →Object reference; storeObject referencetob - load from
a→Object reference; load fromb→null; callequalsonObject referencewith arguments (null) →boolean false; storeboolean falsetoc
- declare
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 falsetoc - declare
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
- 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
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.boolean a = true; boolean b = false; a = a != false; b = a != b;- declare
boolean a; storeboolean truetoa - declare
boolean b; storeboolean falsetob - load from
a→boolean true; equality not equalsboolean trueandboolean false→boolean true; storeboolean truetoa - load from
a→boolean true; load fromb→boolean false; equality not equalsboolean trueandboolean false→boolean true; storeboolean truetob
- declare
Equality not equals with primitive types.
int a = 1; double b = 2.0; boolean c = a != b; c = 1 != a;- declare
int a; storeint 1toa - declare
double b; storedouble 1.0tob - declare
boolean c; load froma→int 1; load fromb→double 2.0; promoteint 1anddouble 2.0: resultdouble; implicit castint 1todouble 1.0→double1.0; equality not equalsdouble 1.0anddouble 2.0→boolean true; storeboolean truetoc` - load from
a→int 1 @1; equality not equalsint 1 @0andint 1 @1→boolean false; storeboolean falsetoc
- declare
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 referencetoa - declare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetob - load 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 truetoc - load 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
- declare
Equality 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; storenulltoa - declare
Object b; storenulltob - declare
boolean c; load froma→null @0; equality not equalsnull @0andnull @1→boolean false; storeboolean falsetoc - load from
a→null @0; load fromb→null @1; equality not equalsnull @0andnull @1→boolean false; storeboolean falsetoc - allocate
Objectinstance →Object reference; storeObject referencetob - load from
a→Object reference; load fromb→null; callequalsonObject referencewith arguments (null) →boolean false; boolean notboolean false→boolean true; storeboolean truetoc
- declare
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 falsetoc - declare
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
- 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
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.
List a = new ArrayList(); List b = new ArrayList(); List c = a; boolean c = a === b; c = a === c;- declare
List a; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetoa - declare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetob - load from
a→List reference; storeList referencetoc - declare
boolean c; load froma→List reference @0; load fromb→List reference @1; identity equalsList reference @0andList reference @1→boolean falsestoreboolean falsetoc - load 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)
- declare
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; storenulltoa - declare
Object b; storenulltob - declare
boolean c; load froma→null @0; identity equalsnull @0andnull @1→boolean true; storeboolean truetoc - load from
a→null @0; load fromb→null @1; identity equalsnull @0andnull @1→boolean true; storeboolean truetoc - allocate
Objectinstance →Object reference; storeObject referencetob - load from
a→Object reference; load fromb→null; identity equalsObject referenceandnull→boolean false; storeboolean falsetoc
- declare
Identity equals with the
deftype.def a = new HashMap(); def b = new ArrayList(); boolean c = a === b; b = a; c = a === b;- declare
def d; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetodef→defstoredeftod - declare
def e; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→defstoredeftod - declare
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 falsetoc - load from
a→def; storedeftob - load 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)
- 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
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.
List a = new ArrayList(); List b = new ArrayList(); List c = a; boolean c = a !== b; c = a !== c;- declare
List a; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetoa - declare
List b; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetoList reference→List reference; storeList referencetob - load from
a→List reference; storeList referencetoc - declare
boolean c; load froma→List reference @0; load fromb→List reference @1; identity not equalsList reference @0andList reference @1→boolean truestoreboolean truetoc - load 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)
- declare
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; storenulltoa - declare
Object b; storenulltob - declare
boolean c; load froma→null @0; identity not equalsnull @0andnull @1→boolean false; storeboolean falsetoc - load from
a→null @0; load fromb→null @1; identity not equalsnull @0andnull @1→boolean false; storeboolean falsetoc - allocate
Objectinstance →Object reference; storeObject referencetob - load from
a→Object reference; load fromb→null; identity not equalsObject referenceandnull→boolean true; storeboolean truetoc
- declare
Identity not equals with the
deftype.def a = new HashMap(); def b = new ArrayList(); boolean c = a !== b; b = a; c = a !== b;- declare
def d; allocateHashMapinstance →HashMap reference; implicit castHashMap referencetodef→defstoredeftod - declare
def e; allocateArrayListinstance →ArrayList reference; implicit castArrayList referencetodef→defstoredeftod - declare
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 truetoc - load from
a→def; storedeftob - load 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)
- 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
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.boolean x = false; boolean y = x ^ true; y = y ^ x;- declare
boolean x; storeboolean falsetox - declare
boolean y; load fromx→boolean falseboolean xorboolean falseandboolean true→boolean true; storeboolean truetoy - load from
y→boolean true @0; load fromx→boolean true @1; boolean xorboolean true @0andboolean true @1→boolean false; storeboolean falsetoy
- declare
Boolean xor with the
deftype.def x = false; def y = x ^ true; y = y ^ x;- declare
def x; implicit castboolean falsetodef→def; storedeftox - declare
def y; load fromx→def; implicit castdeftoboolean false→boolean false; boolean xorboolean falseandboolean true→boolean true; implicit castboolean truetodef→def; storedeftoy - load 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
- 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
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.boolean x = true; boolean y = x && true; x = false; y = y && x;- declare
boolean x; storeboolean truetox - declare
boolean y; load fromx→boolean true @0; boolean andboolean true @0andboolean true @1→boolean true; storeboolean truetoy - store
boolean falsetox - load from
y→boolean true; load fromx→boolean false; boolean andboolean trueandboolean false→boolean false; storeboolean falsetoy
- declare
Boolean and with the
deftype.def x = true; def y = x && true; x = false; y = y && x;- declare
def x; implicit castboolean truetodef→def; storedeftox - declare
def y; load fromx→def; implicit castdeftoboolean true @0→boolean true @0; boolean andboolean true @0andboolean true @1→boolean true; implicit castboolean truetodef→def; storedeftoy - implicit 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
- 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
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.boolean x = false; boolean y = x || true; y = false; y = y || x;- declare
boolean x; storeboolean falsetox - declare
boolean y; load fromx→boolean false; boolean orboolean falseandboolean true→boolean true; storeboolean truetoy - store
boolean falsetoy - load from
y→boolean false @0; load fromx→boolean false @1; boolean orboolean false @0andboolean false @1→boolean false; storeboolean falsetoy
- declare
Boolean or with the
deftype.def x = false; def y = x || true; y = false; y = y || x;- declare
def x; implicit castboolean falsetodef→def; storedeftox - declare
def y; load fromx→def; implicit castdeftoboolean false→boolean true; boolean orboolean falseandboolean true→boolean true; implicit castboolean truetodef→def; storedeftoy - implicit 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
- declare