@JvmStatic๋ž€?

  • Kotlin ํ”„๋กœํผํ‹ฐ๋ฅผ ์ž๋ฐ” ํ•„๋“œ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜

@JvmStatic ์‚ฌ์šฉ๋ฒ•

class C { 
	companion object { 
		@JvmStatic 
		fun callStatic() {} 
		fun callNonStatic() {} 
	} 
}
C.callStatic(); // works fine 
C.callNonStatic(); // error: not a static method 
C.Companion.callStatic(); // instance method remains 
C.Companion.callNonStatic(); // the only way it works
  • @JvmStatic ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ, Companion ํ‚ค์›Œ๋“œ ์—†์ด ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Œ

Reference

  • https://kotlinlang.org/docs/java-to-kotlin-interop.html#static-methods

Last updated