Implicit conversions for value class types?

I read about implicit conversions between different types of value classes. The book "Programming in Scala" states:

[...] an instance of a class scala.Intautomatically expands (by implicit conversion) into an instance of the class scala.Longwhen required.

(chapter 11.1 - Scala Hierarchy)

What does “required” mean in this case? How can this be made "visible"? I assumed:

scala> var i = Int.MaxValue
i: Int = 2147483647

I expected i: Long = 2147483648to add 1.

scala> i = i + 1
i: Int = -2147483648

I did not expect to see an overflow.

+3
source share
1 answer

"Required" means the method in which Long is passed to Int and the like.

Int.+ Long. , Ints , Java- .

+6

Source: https://habr.com/ru/post/1774416/


All Articles