I am aware of this question having been asked several times (eg. Kotlin, generic operation on Number), but unfortunately, in my case the answers are not satisfactory.
The situation is this: I'm writing a vector class in Kotlin, and I want it to be able to store values of any numerical value. But there are two problems:
- Apparently, there is no general way to obtain a zero, which I would need for initialising certain important variables. For instance, BigInteger has its own zero in its companion object.
- Then, the operators don't seem to be defined.
Note in particular that I do have my own numerical data type (BigRational) which I want to use in vectors, and I also want the vector class to handle all possible numerical types.
I'd imagine that if there were a good way to assert that operators exist, then the second problem could be solved. I am at a loss regarding the first one.
I would greatly appreciate any help. Thank you very much!