"as Number" vs. "as DecimalType"

I recently went through my rules and realized that I have used both as Number and as DecimalType.
What’s the difference between the two and what’s the best practice for using one or another? Thanks!

If you look at the class hierarchy it looks something like this:

   /      \
   |      |
Number  State
   |      |

NOTE: the above is notional, I think there is more stuff between State and Object

So what you get with DecimalType is an object that is both a Number and a State but when you use as Number you only have an object that is a Number.

Is there a best practice? I don’t know. I personally would recommend using as Number unless you know for sure you need to do something to it that requires it to be a state. There is one weird case where if one calls MyNumberItem.sendCommand(MyDecialType) where you will get an ambiguous method call exception because there is both a sendCommand(Number) and a sendCommand(DecimalType) and it doesn’t know which one you mean. But if you use as Number that error will go away.

1 Like

Thank you, Rich. Will try to stay with Number and watch for errors.