0

in the below 2 posted examples, i am trying to convert the java code to kotlin code.

the kotlin code does not work and IntelliJ says that I should use companion object.

please let me know how to correct this error.

code_kotlin*

 @SpringBootApplication
 class MyApplication {
 }

 fun main(args: Array<String>) {
 SpringApplication.run(MyApplication::class.java, *args)
 }

codeJava

 @SpringBootApplication
 public class MyApplication {  
 public static void main(String[] args) {
    SpringApplication.run(MyApplication.class, args);
 }       
 }            
Amrmsmb
  • 1
  • 27
  • 104
  • 226

2 Answers2

0

Include main function inside Application class, as Java code does:

 @SpringBootApplication
 class MyApplication {

   fun main(args: Array<String>) {
     SpringApplication.run(MyApplication::class.java, *args)
   }

}
S-Sh
  • 3,564
  • 3
  • 15
  • 19
0

Unlike Java or C#, Kotlin doesn’t have static members or member functions. Kotlin recommends to simply use package-level functions instead. For more detail you can get help from link. You can call companion object like-

class YourClassName{

    companion object {
         //write what you want to make static
    }  
}
Hari N Jha
  • 484
  • 1
  • 3
  • 11