data 类生成的 componentN() 方法的调用。
Kotlin 数据类会自动生成位置 component1()、component2() 以及类似方法,用于析构。 从 Java 中直接调用这些方法不稳定:索引与属性之间的映射不直观,且一旦属性重新排序,这些调用会静默中断。 使用命名属性 getter 更清晰,且重构时更安全。
示例:
String name = person.component1();
int age = person.component2();
在应用快速修复后:
String name = person.getName();
int age = person.getAge();