Hi Everyone ~
My first post here. I’m new to kotlin but fell deep in love with it
I’m currently learning kotlin by writing some simple programs.
I’m also learning how to use netty by the time, so it came naturally that I’m rewriting netty examples with Kotlin! And it’s FUN
But here is my first question:
It seems that in kotlin, unlike java, there can be only one main function in a package.
When writing netty server/client example code, I actually need to start those server/clients to play with, each in a different process of cause. So I need a main function for each of those classes.
for example, two classes in the same package, same .kt file
I can’t write two main functions in this package.
Three solutions I tried:
- Try to put those classes indifferent packages
But this means I’ll have create a new package for EVERY class, which miss the point of package’s organization
- Try put those
mainfunctions in Test code.
But it turned out jUnit test won’t let you run a server, it just exits
- Create an
appspackage where I put all my main functions in it, each with a sub package
This doesn’t hurt the package organization, but it’s still kind of messy, because I’ll have to put them in different .kt files, because you can’t have more than one packages in a file
The 3rd solution is what i’m currently using
Is there a better way ? Thanks