Landry Norris
08/12/2022, 4:49 PMKlitos Kyriacou
08/12/2022, 4:55 PMJoffrey
08/12/2022, 5:07 PMmain()
method to call as the entrypoint of the program.
Now, simple class names are not unique. To really identify a class, you have to tell Java the "fully qualified name" of the class, which is the name of the package in which the class is, followed by a dot, followed by the "simple name" of the class.
When you declare the top-level main()
function in Kotlin, the "main class" to use in order to run it will be the auto-generated class that contains the top-level declarations of the file. As Landry said, this generated class will have a simple name based on the file name (Main.kt
-> MainKt
), and the package of this class will be the package declared in the file (in your case, cinema
).
So in your case, without a package
line at the top of the file, the fully qualified name of the main class is really just MainKt
, but with the package cinema
at the top of the file, the fully qualified name of the main class is cinema.MainKt
.Ben Edwards
08/12/2022, 5:19 PMLandry Norris
08/12/2022, 5:22 PMJoffrey
08/12/2022, 5:23 PMSo does this start with package cinema?Yes, the folder hierarchy is a convention of the placement, but the important bit is the
package cinema
line at the top of the file. This must stay even when you put the file under the src/main/kotlin/cinema
directory.Landry Norris
08/12/2022, 5:23 PMJoffrey
08/12/2022, 5:27 PMLandry Norris
08/12/2022, 5:29 PMBen Edwards
08/12/2022, 5:32 PMJoffrey
08/12/2022, 5:33 PMpackage cinema
in src/main/kotlin/Main.kt
because this location matches the other convention.Ben Edwards
08/12/2022, 5:35 PMJoffrey
08/12/2022, 5:37 PMBen Edwards
08/12/2022, 5:57 PM