That is not true: “It is not required to match dir...
# announcements
d
That is not true: “It is not required to match directories and packages: source files can be placed arbitrarily in the file system.” — Language Guide https://kotlinlang.org/docs/reference/basic-syntax.html
v
Is it not?
t
I'd say its an antipattern, but should not keep you from compiling your code (in kotlin that is, java is different here). You will get warnings in your IDE, but it still works.
Actually I remember having that in a work project after someone messed up the directory structure while refactoring some code.
v
Wasn't it even in Java the same?
t
not sure tbh. Java definitely didn't let you name the class different from the file
v
Yes and no, you can have multiple classes in one file. But the statement was only about packages and directories, not classes and files.
t
just changed a direcory on an old java project, still compiles. So yes, you can actually place your files anywhere. But please don't do it.
v
Yeah, thought so. :-)
d
You can place it anywhere only if package declaration is not given to source file. When your source file contains
package org.example
you get unresolved reference for example in your main file. So this “It is not required to match directories and packages: source files can be placed arbitrarily in the file system.” is written directly after this:
Copy code
package my.demo

import kotlin.text.*

// ...
and that is wrong. :-)
t
I don't know what's odd with your setup, but usually that is no issue