Skip to content

Instantly share code, notes, and snippets.

@runarorama
Last active August 29, 2015 13:59
Show Gist options
  • Save runarorama/10997462 to your computer and use it in GitHub Desktop.
Save runarorama/10997462 to your computer and use it in GitHub Desktop.
scala> 0.toByte.toInt
res5: Int = 0
scala> 0.toByte.toInt.abs
<console>:8: error: implicit numeric widening
0.toByte.toInt.abs
^
scala> res5.abs
res7: Int = 0
scala> 0
res8: Int = 0
scala> res8.toByte.toInt
res9: Int = 0
scala> (0:Int).toByte.toInt.abs
<console>:8: error: implicit numeric widening
(0:Int).toByte.toInt.abs
^
scala> 0.toInt.abs
<console>:8: error: implicit numeric widening
0.toInt.abs
^
@jamie-allen
Copy link

Why not just say (0.toByte.toInt).abs? Works fine.

scala> (0.toByte.toInt).abs
res3: Int = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment