Skip to main content
text formatting
Source Link
barbsan
  • 3.5k
  • 11
  • 23
  • 29

In Java, we can write in below way

In Java, we can write in below way class MyClass { public static int myMethod() { return 1; } } In Kotlin, we can write in below way  

In Kotlin, we can write in below way

class MyClass { companion object { fun myMethod() : Int = 1 } }   a companion is used as static in Kotlin. 

a companion is used as static in Kotlin.

In Java, we can write in below way class MyClass { public static int myMethod() { return 1; } } In Kotlin, we can write in below way  class MyClass { companion object { fun myMethod() : Int = 1 } }   a companion is used as static in Kotlin. 

In Java, we can write in below way

class MyClass { public static int myMethod() { return 1; } } 

In Kotlin, we can write in below way

class MyClass { companion object { fun myMethod() : Int = 1 } } 

a companion is used as static in Kotlin.

Source Link
Nikhil Katekhaye
  • 2.7k
  • 1
  • 21
  • 19

In Java, we can write in below way class MyClass { public static int myMethod() { return 1; } } In Kotlin, we can write in below way class MyClass { companion object { fun myMethod() : Int = 1 } } a companion is used as static in Kotlin.