It is hard to fully explain without a lot of text. At a very high level openHAB is written in an Object Oriented (OO) language. One aspect of OO is that you have Objects which are a bundle of data and methods that operate on that data. When you use MyItem.sendCommand
in a Rule you are calling the sendCommand method on the MyItem object.
Objects can have two relationships: “has a” and “is a”
The “has a” relationship means that one Object contains another object. I won’t go into details as it doesn’t address your question.
In an OO language one defines the data and methods by creating a Class. A Class is like the blueprint for building Objects and an Object is an instance of a Class.
When a programmer defines a Class they can use a concept called Inheritance. Inheritance lets you make a Class (and therefore Objects created from that Class) extend or change an already existing Class. This extension is an “is a” relationship. Because the new Class extends the old Class the rest of the program can treat the new one as if it were the old one.
Thus one creates a hierarchy of Classes that all inherit from each other and you can treat any Class at the bottom of the hierarchy as if it were one of its ancestors.
In this particular case the family tree would looks something like this:
Object
/ \
Number Command
\ /
DecimalType
I think there are some more steps between Number and DecimalType but lets pretend it looks like the above.
So at the root is Object. Almost everything in the Rules is an Object. Next we have Number and Command. Both inherit from Object but they are siblings so you cannot treat a Number like a Command. However, DecimalType inherits from both Number and Command so depending on the context and what you need you can treat a DecimalType as a Number or as a Command or as a DecimalType.
When I say “treat like” what I mean is DecimalType has the same data and the same methods that a Number has so your can cast a DecimalType to Number without problem and any method that Number has DecimalType also has (e.g. DecimalType has an intValue method because Number does). Likewise, DecimalType has the same data and methods as Command so you can cast it to Command as well.
You had that first error because there are two sendCommands, one that takes a Number and one that takes a Command. Because DecimalType is both it didn’t know which one you really meant it to be.