public static void main in Kotlin
In Java
, especially in Android studio
, every time that I want to run or test some Java
source code quickly, I will create public static void main
(shortkey: psvm + tab
) and the IDE will show "Play" button to run it immediately.
Do we have some kind of psvm
in Kotlin
- an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic
). Can we config somewhere in Android studio
?
fun main(args: Array<String>) {
}
java android android-studio kotlin
add a comment |
In Java
, especially in Android studio
, every time that I want to run or test some Java
source code quickly, I will create public static void main
(shortkey: psvm + tab
) and the IDE will show "Play" button to run it immediately.
Do we have some kind of psvm
in Kotlin
- an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic
). Can we config somewhere in Android studio
?
fun main(args: Array<String>) {
}
java android android-studio kotlin
I think you need to put it inside a companion object with the @JvmStatic annotation.
– TheWanderer
Dec 31 '18 at 16:33
It works. Thank you @TheWanderer.
– nhp
Dec 31 '18 at 16:35
add a comment |
In Java
, especially in Android studio
, every time that I want to run or test some Java
source code quickly, I will create public static void main
(shortkey: psvm + tab
) and the IDE will show "Play" button to run it immediately.
Do we have some kind of psvm
in Kotlin
- an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic
). Can we config somewhere in Android studio
?
fun main(args: Array<String>) {
}
java android android-studio kotlin
In Java
, especially in Android studio
, every time that I want to run or test some Java
source code quickly, I will create public static void main
(shortkey: psvm + tab
) and the IDE will show "Play" button to run it immediately.
Do we have some kind of psvm
in Kotlin
- an entry point or something in order to run or test anything that quickly? Did try with this function but it wasn't working. (Even try with @JvmStatic
). Can we config somewhere in Android studio
?
fun main(args: Array<String>) {
}
java android android-studio kotlin
java android android-studio kotlin
asked Dec 31 '18 at 16:32
nhpnhp
1,900414
1,900414
I think you need to put it inside a companion object with the @JvmStatic annotation.
– TheWanderer
Dec 31 '18 at 16:33
It works. Thank you @TheWanderer.
– nhp
Dec 31 '18 at 16:35
add a comment |
I think you need to put it inside a companion object with the @JvmStatic annotation.
– TheWanderer
Dec 31 '18 at 16:33
It works. Thank you @TheWanderer.
– nhp
Dec 31 '18 at 16:35
I think you need to put it inside a companion object with the @JvmStatic annotation.
– TheWanderer
Dec 31 '18 at 16:33
I think you need to put it inside a companion object with the @JvmStatic annotation.
– TheWanderer
Dec 31 '18 at 16:33
It works. Thank you @TheWanderer.
– nhp
Dec 31 '18 at 16:35
It works. Thank you @TheWanderer.
– nhp
Dec 31 '18 at 16:35
add a comment |
3 Answers
3
active
oldest
votes
You can just put the main function outside of any class.
In anyFile.kt do:
package foo
fun main(args: Array<String>) {
}
Either main + tab
or psvm + tab
work if you have your cursor outside of a class.
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
add a comment |
Put it inside a companion object with the @JvmStatic
annotation:
class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}
add a comment |
Yes, shortkey: main + tab in any kotlin file
It will generate
fun main(args: Array<String>) {
}
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
@leonardkraemer, The question was about how to generatemain
function quickly
– Omar Mainegra
Dec 31 '18 at 16:55
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
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%2f53989520%2fpublic-static-void-main-in-kotlin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can just put the main function outside of any class.
In anyFile.kt do:
package foo
fun main(args: Array<String>) {
}
Either main + tab
or psvm + tab
work if you have your cursor outside of a class.
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
add a comment |
You can just put the main function outside of any class.
In anyFile.kt do:
package foo
fun main(args: Array<String>) {
}
Either main + tab
or psvm + tab
work if you have your cursor outside of a class.
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
add a comment |
You can just put the main function outside of any class.
In anyFile.kt do:
package foo
fun main(args: Array<String>) {
}
Either main + tab
or psvm + tab
work if you have your cursor outside of a class.
You can just put the main function outside of any class.
In anyFile.kt do:
package foo
fun main(args: Array<String>) {
}
Either main + tab
or psvm + tab
work if you have your cursor outside of a class.
edited Dec 31 '18 at 16:59
answered Dec 31 '18 at 16:41
leonardkraemerleonardkraemer
3,44111532
3,44111532
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
add a comment |
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
Outside of any class is the point. Thank you
– nhp
Dec 31 '18 at 16:59
add a comment |
Put it inside a companion object with the @JvmStatic
annotation:
class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}
add a comment |
Put it inside a companion object with the @JvmStatic
annotation:
class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}
add a comment |
Put it inside a companion object with the @JvmStatic
annotation:
class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}
Put it inside a companion object with the @JvmStatic
annotation:
class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}
answered Dec 31 '18 at 16:40
TheWandererTheWanderer
7,44521129
7,44521129
add a comment |
add a comment |
Yes, shortkey: main + tab in any kotlin file
It will generate
fun main(args: Array<String>) {
}
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
@leonardkraemer, The question was about how to generatemain
function quickly
– Omar Mainegra
Dec 31 '18 at 16:55
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
add a comment |
Yes, shortkey: main + tab in any kotlin file
It will generate
fun main(args: Array<String>) {
}
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
@leonardkraemer, The question was about how to generatemain
function quickly
– Omar Mainegra
Dec 31 '18 at 16:55
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
add a comment |
Yes, shortkey: main + tab in any kotlin file
It will generate
fun main(args: Array<String>) {
}
Yes, shortkey: main + tab in any kotlin file
It will generate
fun main(args: Array<String>) {
}
edited Dec 31 '18 at 16:55
answered Dec 31 '18 at 16:47
Omar MainegraOmar Mainegra
2,3871020
2,3871020
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
@leonardkraemer, The question was about how to generatemain
function quickly
– Omar Mainegra
Dec 31 '18 at 16:55
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
add a comment |
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
@leonardkraemer, The question was about how to generatemain
function quickly
– Omar Mainegra
Dec 31 '18 at 16:55
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
This does not work inside of a class. (And that was the confusion)
– leonardkraemer
Dec 31 '18 at 16:53
@leonardkraemer, The question was about how to generate
main
function quickly– Omar Mainegra
Dec 31 '18 at 16:55
@leonardkraemer, The question was about how to generate
main
function quickly– Omar Mainegra
Dec 31 '18 at 16:55
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
psvm + tab works as well, just not inside a class.
– leonardkraemer
Dec 31 '18 at 16:56
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
Thanks @OmarMainegra, main + tab works, so does psvm + tab (outside the class). But @ leonardkraemer's answer looks good to me.
– nhp
Dec 31 '18 at 17:01
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%2f53989520%2fpublic-static-void-main-in-kotlin%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
I think you need to put it inside a companion object with the @JvmStatic annotation.
– TheWanderer
Dec 31 '18 at 16:33
It works. Thank you @TheWanderer.
– nhp
Dec 31 '18 at 16:35