How should I check a long to see if it has a value or is null?

Hi All,
I am doing some clean up and I cam across some loading warnings for a rule that say

The operator '!==' is undefined for the argument types long and null
The operator '===' is undefined for the argument types long and null

I can see that I am indeed comparing defined long type variable with null, here is such an example:

DWEnabled is type long

	if (DWEnabled!==null) {
		logInfo("DW_Appliance.rules", "DWEnabled: "+DWEnabled)
		val long DWElapsedTime = DWDisabled - DWEnabled
		val long DWElapsedTimeMin = DWElapsedTime / 1000 / 60
		logInfo("DW_Appliance.rules", "  DW was INUSE for "+ DWElapsedTimeMin + "Mins.")

How do I keep the outcome intent in this situation?

I am wondering if I should only use == instead of === for long types, or possible use
Perhaps a defined long can never be null??? or I use the example I found in jave;

if (DWEnabled.isNull) {
  do stuff
} else {
  do other stuff

I am sure for seasoned coders this is a newbie question but as a project level coder its not clear.


How about

DWEnabled.state != NULL

I have previously understood null and NULL to not be the same.
I am currently trying

DWEnabled.state != null

Are you saying that it is NULL in this case instead of null or just offering up ideas?


I’m not sure how Xtend handles primitives, but in java, primitives can’t have the value null. Primitive numeric types (byte, short, int, long, float and double) has a default value of 0.

On the other hand, it’s not recommended to use primitives in rules, for performance reasons (there are other threads about it, IIRC it makes rule load much slower), so it’s better to use Number type instead. Since Number is an object, it can be null as well, so your code would work better.

If it is an item you have to check the state.
The item name will give an error.