What is the differences between Int and Integer in Scala?

后端 未结 5 2050
无人及你
无人及你 2020-12-01 17:46

I was working with a variable that I had declared as an Integer and discovered that > is not a member of Integer. Here\'s a simple example:

scala> i
warni         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 18:18

    I think the problem you're seeing has has to do boxing/unboxing of value types and the use of the Java class Integer.

    I think the answer is here: Boxing and unboxing in Scala. There is no implict unboxing in Scala. You've defined i as the Java class Integer but in the i > 3, the 3 is being treated and an int.

提交回复
热议问题