why is main(args: Array) allowed to be defined in more than one fileWhat is the difference between main and regular function?Error: Execution failed for task ':app:clean'. Unable to delete fileConfiguring Gradle with KotlinHow can I get my JUnit tests to compile and run in my Kotlin+Gradle project?Android Kotlin : Error Unresolved reference: DaggerAppComponentWhy does Kotlin allow having two classes with same name and package in different folders (i.e.: main and androidTest)?Unresolved reference when referencing Java code from Kotlin tests in Spring Boot project using GradleWhat is the difference between main and regular function?Why aren't “internal” types in the main source tree visible in my unit tests?Failsafe withFallback(): why kotlin compiler fails to infer lambda type?Can Gradle produce multiple Kotlin Native binaries (for one OS)?
Why didn't Voldemort recognize that Dumbledore was affected by his curse?
Is it expected that a reader will skip parts of what you write?
Writing an augmented sixth chord on the flattened supertonic
How did old MS-DOS games utilize various graphic cards?
Who enforces MPAA rating adherence?
If I leave the US through an airport, do I have to return through the same airport?
Meaning of 'lose their grip on the groins of their followers'
Who won a Game of Bar Dice?
How to ensure color fidelity of the same file on two computers?
Does Disney no longer produce hand-drawn cartoon films?
I have a problematic assistant manager, but I can't fire him
How to use memset in c++?
Which languages would be most useful in Europe at the end of the 19th century?
Why is a common reference string needed in zero knowledge proofs?
Thread Pool C++ Implementation
Why does logistic function use e rather than 2?
How to trick the reader into thinking they're following a redshirt instead of the protagonist?
Interval of parallel 5ths in the resolution of a German 6th chord
You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one
How is the excise border managed in Ireland?
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
Cascading Switches. Will it affect performance?
Does the Long March-11 increase its thrust after clearing the launch tower?
Why did Sanhedrin deal with who has a share in Olam Habah?
why is main(args: Array) allowed to be defined in more than one file
What is the difference between main and regular function?Error: Execution failed for task ':app:clean'. Unable to delete fileConfiguring Gradle with KotlinHow can I get my JUnit tests to compile and run in my Kotlin+Gradle project?Android Kotlin : Error Unresolved reference: DaggerAppComponentWhy does Kotlin allow having two classes with same name and package in different folders (i.e.: main and androidTest)?Unresolved reference when referencing Java code from Kotlin tests in Spring Boot project using GradleWhat is the difference between main and regular function?Why aren't “internal” types in the main source tree visible in my unit tests?Failsafe withFallback(): why kotlin compiler fails to infer lambda type?Can Gradle produce multiple Kotlin Native binaries (for one OS)?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have defined main(args: Array) in two Kotlin files in the same package. The compiler does not complain. Why not?
I am using IntelliJ IDEA with Gradle
#file1.kt
package test
fun main(args: Array<String>)
#file2.kt
package test
fun main(args: Array<String>)
kotlin
|
show 3 more comments
I have defined main(args: Array) in two Kotlin files in the same package. The compiler does not complain. Why not?
I am using IntelliJ IDEA with Gradle
#file1.kt
package test
fun main(args: Array<String>)
#file2.kt
package test
fun main(args: Array<String>)
kotlin
Why should it complain? These are two separate entry points... if you want to run the program you need to know exactly which one you want to use.
– Moira
Mar 24 at 17:23
@Moira Suppose you want to call one of them from a class in another package, how would you import it and make sure you don't import the other one? Other functions than main do cause an ambiguity error.
– JB Nizet
Mar 24 at 17:36
@Moira Can we define main() in the 2 files? Answer is not.
– user1443721
Mar 24 at 17:39
Fair enough, good point. I wonder what happens if you try to invokemain
? (edit: you get an error)
– Moira
Mar 24 at 17:46
1
It's not supposed to complain when you have it in two different files. You can do the same with Java, because the main function always points to a Java class, not a package. The code compiles tofile[num]Kt.java
, which means two separate classes. It's by design, and is also valid in Java
– Zoe
Mar 24 at 18:59
|
show 3 more comments
I have defined main(args: Array) in two Kotlin files in the same package. The compiler does not complain. Why not?
I am using IntelliJ IDEA with Gradle
#file1.kt
package test
fun main(args: Array<String>)
#file2.kt
package test
fun main(args: Array<String>)
kotlin
I have defined main(args: Array) in two Kotlin files in the same package. The compiler does not complain. Why not?
I am using IntelliJ IDEA with Gradle
#file1.kt
package test
fun main(args: Array<String>)
#file2.kt
package test
fun main(args: Array<String>)
kotlin
kotlin
edited Mar 24 at 18:59
user1443721
asked Mar 24 at 17:18
user1443721user1443721
2141518
2141518
Why should it complain? These are two separate entry points... if you want to run the program you need to know exactly which one you want to use.
– Moira
Mar 24 at 17:23
@Moira Suppose you want to call one of them from a class in another package, how would you import it and make sure you don't import the other one? Other functions than main do cause an ambiguity error.
– JB Nizet
Mar 24 at 17:36
@Moira Can we define main() in the 2 files? Answer is not.
– user1443721
Mar 24 at 17:39
Fair enough, good point. I wonder what happens if you try to invokemain
? (edit: you get an error)
– Moira
Mar 24 at 17:46
1
It's not supposed to complain when you have it in two different files. You can do the same with Java, because the main function always points to a Java class, not a package. The code compiles tofile[num]Kt.java
, which means two separate classes. It's by design, and is also valid in Java
– Zoe
Mar 24 at 18:59
|
show 3 more comments
Why should it complain? These are two separate entry points... if you want to run the program you need to know exactly which one you want to use.
– Moira
Mar 24 at 17:23
@Moira Suppose you want to call one of them from a class in another package, how would you import it and make sure you don't import the other one? Other functions than main do cause an ambiguity error.
– JB Nizet
Mar 24 at 17:36
@Moira Can we define main() in the 2 files? Answer is not.
– user1443721
Mar 24 at 17:39
Fair enough, good point. I wonder what happens if you try to invokemain
? (edit: you get an error)
– Moira
Mar 24 at 17:46
1
It's not supposed to complain when you have it in two different files. You can do the same with Java, because the main function always points to a Java class, not a package. The code compiles tofile[num]Kt.java
, which means two separate classes. It's by design, and is also valid in Java
– Zoe
Mar 24 at 18:59
Why should it complain? These are two separate entry points... if you want to run the program you need to know exactly which one you want to use.
– Moira
Mar 24 at 17:23
Why should it complain? These are two separate entry points... if you want to run the program you need to know exactly which one you want to use.
– Moira
Mar 24 at 17:23
@Moira Suppose you want to call one of them from a class in another package, how would you import it and make sure you don't import the other one? Other functions than main do cause an ambiguity error.
– JB Nizet
Mar 24 at 17:36
@Moira Suppose you want to call one of them from a class in another package, how would you import it and make sure you don't import the other one? Other functions than main do cause an ambiguity error.
– JB Nizet
Mar 24 at 17:36
@Moira Can we define main() in the 2 files? Answer is not.
– user1443721
Mar 24 at 17:39
@Moira Can we define main() in the 2 files? Answer is not.
– user1443721
Mar 24 at 17:39
Fair enough, good point. I wonder what happens if you try to invoke
main
? (edit: you get an error)– Moira
Mar 24 at 17:46
Fair enough, good point. I wonder what happens if you try to invoke
main
? (edit: you get an error)– Moira
Mar 24 at 17:46
1
1
It's not supposed to complain when you have it in two different files. You can do the same with Java, because the main function always points to a Java class, not a package. The code compiles to
file[num]Kt.java
, which means two separate classes. It's by design, and is also valid in Java– Zoe
Mar 24 at 18:59
It's not supposed to complain when you have it in two different files. You can do the same with Java, because the main function always points to a Java class, not a package. The code compiles to
file[num]Kt.java
, which means two separate classes. It's by design, and is also valid in Java– Zoe
Mar 24 at 18:59
|
show 3 more comments
1 Answer
1
active
oldest
votes
Would the compiler complain if it was Java? No.
Since main method is an entry point to your application, the problem can arise only when there is ambiguity in the application that you are trying to compose. In your question, you haven't provided any specifics about your application. Those 2 files can be completely unaware of each other for what it's worth.
It can be a problem at startup, but even that would rarely happen these days. Modern frameworks, like Spring Boot, have their own way to identify where to start your application, that is where the entry point is.
They make use of their specific MANIFEST files and context/class loaders and project structures.
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326422%2fwhy-is-mainargs-arraystring-allowed-to-be-defined-in-more-than-one-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Would the compiler complain if it was Java? No.
Since main method is an entry point to your application, the problem can arise only when there is ambiguity in the application that you are trying to compose. In your question, you haven't provided any specifics about your application. Those 2 files can be completely unaware of each other for what it's worth.
It can be a problem at startup, but even that would rarely happen these days. Modern frameworks, like Spring Boot, have their own way to identify where to start your application, that is where the entry point is.
They make use of their specific MANIFEST files and context/class loaders and project structures.
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
add a comment |
Would the compiler complain if it was Java? No.
Since main method is an entry point to your application, the problem can arise only when there is ambiguity in the application that you are trying to compose. In your question, you haven't provided any specifics about your application. Those 2 files can be completely unaware of each other for what it's worth.
It can be a problem at startup, but even that would rarely happen these days. Modern frameworks, like Spring Boot, have their own way to identify where to start your application, that is where the entry point is.
They make use of their specific MANIFEST files and context/class loaders and project structures.
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
add a comment |
Would the compiler complain if it was Java? No.
Since main method is an entry point to your application, the problem can arise only when there is ambiguity in the application that you are trying to compose. In your question, you haven't provided any specifics about your application. Those 2 files can be completely unaware of each other for what it's worth.
It can be a problem at startup, but even that would rarely happen these days. Modern frameworks, like Spring Boot, have their own way to identify where to start your application, that is where the entry point is.
They make use of their specific MANIFEST files and context/class loaders and project structures.
Would the compiler complain if it was Java? No.
Since main method is an entry point to your application, the problem can arise only when there is ambiguity in the application that you are trying to compose. In your question, you haven't provided any specifics about your application. Those 2 files can be completely unaware of each other for what it's worth.
It can be a problem at startup, but even that would rarely happen these days. Modern frameworks, like Spring Boot, have their own way to identify where to start your application, that is where the entry point is.
They make use of their specific MANIFEST files and context/class loaders and project structures.
answered Mar 24 at 19:32
yuranos87yuranos87
1,90822330
1,90822330
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
add a comment |
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
It is different in Java. The main method in Java is defined inside the class. Here in Kotlin, the main function is top level. Also I do mention the 2 files are in the same package. Even though developers may not be aware it, the compiler will. Try define main() in both files to see what happens.
– user1443721
Mar 25 at 4:24
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
I did try to add a file beside my main application file and it still compiles and works without problem. You should provide more context probably. Everything compiles down to Java classes, the only difference with Kotlin is that the classes will have "Kt" in the end.
– yuranos87
Mar 25 at 8:25
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
did you try main() in the 2 files? I mean main(), not main(args: Array<String>)
– user1443721
Mar 26 at 3:20
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
Ah, got your point. But still, the problems only happen when I try to build a Spring Boot executable by calling bootRun or bootJar. If I only run gradle compileKotlin everything if fine. So we are back to the questions "Why should Kotlin compiler bother?"
– yuranos87
Mar 26 at 6:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326422%2fwhy-is-mainargs-arraystring-allowed-to-be-defined-in-more-than-one-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why should it complain? These are two separate entry points... if you want to run the program you need to know exactly which one you want to use.
– Moira
Mar 24 at 17:23
@Moira Suppose you want to call one of them from a class in another package, how would you import it and make sure you don't import the other one? Other functions than main do cause an ambiguity error.
– JB Nizet
Mar 24 at 17:36
@Moira Can we define main() in the 2 files? Answer is not.
– user1443721
Mar 24 at 17:39
Fair enough, good point. I wonder what happens if you try to invoke
main
? (edit: you get an error)– Moira
Mar 24 at 17:46
1
It's not supposed to complain when you have it in two different files. You can do the same with Java, because the main function always points to a Java class, not a package. The code compiles to
file[num]Kt.java
, which means two separate classes. It's by design, and is also valid in Java– Zoe
Mar 24 at 18:59