我有一个带有模态类 User 的多平台项目。
用户.kt
class User {
val id = -1
val username = ""
val age = -1
val nickname = ""
}
我也有预期和实际的注释
Annotation.kt [通用模块]
expect annotation class NodeEntity
expect annotation class Id
expect annotation class GeneratedValue
此外,我有他们的实际实施
Annotation.kt [JVM 模块]
actual typealias ValueFor = org.neo4j.ogm.annotation.ValueFor
actual typealias NodeEntity = org.neo4j.ogm.annotation.NodeEntity
actual typealias Id = org.neo4j.ogm.annotation.Id
actual typealias GeneratedValue = org.neo4j.ogm.annotation.GeneratedValue
actual typealias Relationship = org.neo4j.ogm.annotation.Relationship
然后我返回并注释了我的 User.kt
@NodeEntity
class User {
@Id
@GeneratedValue
val id = -1
val username = ""
val age = -1
val nickname = ""
}
但是当我编译它时,我得到了这个错误
Task :compileKotlinJvm FAILED
e: ...User.kt: (13, 2): This class does not have a constructor
e: ...User.kt: (21, 6): This class does not have a constructor
e: ...User.kt: (22, 6): This class does not have a constructor
我究竟做错了什么?
注意:B。尝试完成
- 使预期的注释具有构造函数[不成功]
- 使预期注释与构造函数匹配 [错误:参数“{0}”在预期和实际注释中的值冲突]
仅供参考:我的 build.gradle 已经有了 noArg,因此 User.kt 类是使用无参数公共构造函数编译的