guys, I need to emulate java static method in my k...
# getting-started
e
guys, I need to emulate java static method in my kotlin code. I tried to use compain object, but seems it’s a wrong choice:
Copy code
class MyClass {
	companion object {
		fun myCoolStaticMethod() {

		}
	}
}
Java library (junit 5), which expects existing of static method myCoolStaticMethod tell me, that there is no such method in MyClass What I’am doing wrong?
k
evkaky: it only gets exported as an actual static function if you annotate the function with
@JvmStatic
e
wow, thank you, my kotlin-friend
👍 1
j
Kotlin doesn't support static methods, this should only be used to make Kotlin code work with Java code.
k
Yes, by doing this you lose out on some of the nice things that you can do because the functions are non-static. Namely, that you can have method inheritance and that they can be implemented on your companion object off a superclass or interface
it's definitely required when you have Java libraries that are expecting a static method to be there though, like with JUnit