@JvmField ๋ž€?

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

@JvmField ์‚ฌ์šฉ๋ฒ•

class Person {
  @JvmField
  var name: String = "Kotlin"

  // ...
}
Person person = new Person();
person.name = "Java";
String javaName = person.name;
  • kotlin ์—์„œ ํ•ด๋‹น ์–ด๋…ธํ…Œ์ด์…˜์„ ํŠน์ • ํ•„๋“œ ์œ„์— ์„ ์–ธํ•˜๋ฉด,

  • java ์—์„œ get set ์•„๋‹Œ property ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Œ

    • e.g. person.name = "Java";

Reference

  • https://kotlinlang.org/docs/java-to-kotlin-interop.html#instance-fields

Last updated