According to this, Scala 3 offers a new way to define programs that can be invoked from the command line: A
@main annotation on a method turns this method into an executable program.
I followed exactly the code
@main def happyBirthday(age: Int, name: String, others: String*) = val suffix = age % 100 match case 11 | 12 | 13 => "th" case _ => age % 10 match case 1 => "st" case 2 => "nd" case 3 => "rd" case _ => "th" val bldr = new StringBuilder(s"Happy $age$suffix birthday, $name") for other <- others do bldr.append(" and ").append(other) bldr.toString
and compiled it with scalac. Subsequent run produces an error
scala happyBirthday 23 Lisa Peter
Illegal command line: java.lang.NumberFormatException: For input string: “happyBirthday”
It is clear to me that the program name (which should be the argument 0) is mistakenly taken as the first numeric argument. What is the problem and how to solve it?
java -version java version "1.8.0_321" Java(TM) SE Runtime Environment (build 1.8.0_321-b07) Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
scala -version Scala code runner version 3.1.1 -- Copyright 2002-2022, LAMP/EPFL