Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 148 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
public static void main in Kotlin

#1
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.


[![enter image description here][1]][1]

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>) {

}


[1]:
Reply

#2
Put it inside a companion object with the `@JvmStatic` annotation:

class Test {
companion object {
@JvmStatic
fun main(args: Array<String>) {}
}
}
Reply

#3
You can just put the main function outside of any class.

In anyFile.kt do:

package foo

fun main(args: Array<String>) {

}

[![enter image description here][1]][1]

Either `main + tab` or `psvm + tab` work if you have your cursor outside of a class.

[1]:
Reply

#4
Yes, shortkey: *main + <kbd>tab</kbd>* in any *kotlin* file

It will generate

fun main(args: Array<String>) {

}
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through