Hi friends! TIL something interesting. I ended up ...
# getting-started
p
Hi friends! TIL something interesting. I ended up writing this code (actually not this code, which is a MWE):
Copy code
fun main(args: Array<String>) = runCatching { println("Hello world") }
When I ran it, I got
Copy code
Error: Main method not found in class org.example.MainKt, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
I then realized my
main
is not returning
void/Unit
but
Result<Unit>
. Adding
Copy code
fun main(args: Array<String>) = runCatching { println("Hello world") }.getOrThrow()
or anything that would return
Unit
makes the signature match and it works. 🙂
j
You could also use curly braces instead of the expression body. Then you wouldn't need to add anything. 🙂
(Other than the curly braces, I mean. 😅 )
p
Ah yes! 😁 It was a nice exercise to find out!
🙂 1
👍 1