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
apps.netty.time.TimeServerHandler
apps.netty.time.TimeClientHandler
I can’t write two main functions in this package.
Three solutions I tried:
- Try to put those classes indifferent packages
apps.netty.time.server.TimeServerHandler
apps.netty.time.client.TimeClientHandler
But this means I’ll have create a new package for EVERY class, which miss the point of package’s organization
- Try put those
main
functions in Test code.
But it turned out jUnit test won’t let you run a server, it just exits
- Create an
apps
package where I put all my main functions in it, each with a sub package
apps.netty.time.server
apps.netty.time.client
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