Scala for the portable chapter 15 Exercise 10: add assert(n >= 0 to the factorial method. Compile with the statements included and make sure factorial(-1) throws an exception. Compile without statements. What happens? Use javap to check what happened with a confirmation call.
My code is:
object Test { def factorial(x: Int): Int = { assert(x >= 0, "Call to factorial must be >= 0!") x match { case 0 => 1 case x: Int => x * factorial(x - 1) } } def main(args: Array[String]): Unit = { factorial(-1) } }
First I compiled scalac , examined it with javap Test , then compiled again with scalac -Xelide-below MAXIMUM and examined with the same command - I can not find the difference between them.
I understand that compilation with statements throws an exception when trying to execute a program, and compilation without statements will throw an error, but I cannot find the difference in javap ...
source share