What is the differences between Int and Integer in Scala?

后端 未结 5 2061
无人及你
无人及你 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:16

    Integer gets imported from java.lang.Integer and is only for compatibility with Java. Since it is a Java class, of course it can't have a method called "<".

    EDIT: You can mitigate this problem by declaring an implicit conversion from Integer to Int.

提交回复
热议问题