if I have my Main.kt and Foo.kt and Bar.kt in a di...
# getting-started
o
if I have my Main.kt and Foo.kt and Bar.kt in a directory, and Foo and Bar both have classes with the same names, how can I import them into Main.kt? what i’m doing now is assigning the package
<http://com.something.app|com.something.app>
to all of them, and then inside Main.kt I do
import com.something.app.Foo
and attempt to use it inside Main, but it’s undefined the way I’m running Main is just
kotlinc Main.kt -include-runtime -d jar
and then
java -jar thatJar.jr
The docs say if you provide no package, they will all belong to the root package and you can use them freely if they are in the same directory, but even compiling them all isn’t allowing me to do that
j
You don't need the import if they are in the same package, but you do need to compile all the files. Currently you're only compiling
Main.kt
you could compile
*.kt
to compile all your files at the same time
r
How can you have classes with the same names in the same package? That's impossible.
o
Yea I did ‘Kotlinc *.TK’
Autocorrect…
One second
there’s Node.kt, LinkedList.kt, and Runner.kt
all in the same directory
none of them have the package header right now
LinkedList.kt uses Node.kt by creating a new Node, and Runner uses linkeList.kt by creating a new linkedlist
now I do
kotlinc *.kt
and then I go into Runner.kt,
kotlinc Runner.kt ….
and produce a jar and run it, I get that LinkedList is unresolved
ok the jar at the end is including Runner.kt only 🙂
thank you!