最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add two Number generics in Kotlin? - Stack Overflow

programmeradmin4浏览0评论

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:

  1. 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.
  2. 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!

发布评论

评论列表(0)

  1. 暂无评论