Why does Kotlin allow package structure that does not match folder structure?

Viewed 125

Kotlin packages are written package one.two.three, and they usually match the folder structure (e.g. one/two/three) of the project, but they don't have to match the folder structure. What is the motivation behind the decision to allow packages to not match the folder structure? What use cases does it enable?

1 Answers

The obvious use case is that now you can organize your code in whatever packages and you are not forced to have the same folder structure. Other than that I don't see any other use case. Why have they done it? Not sure and it does not seem to be something useful or wanted because the recommendation is still to match packages with the folder structure (even IntelliJ warns you when you have a package that does not match the folder structure.

It seems to me to be a feature that was not needed or even wanted by the community.

Related