代码之家  ›  专栏  ›  技术社区  ›  andylamax

kotlin multiplatform预期的注释返回'this class没有带neo4j实际类型别名的构造函数'

  •  0
  • andylamax  · 技术社区  · 6 年前

    我有一个带有模态类的多平台项目,用户。

    使用户

    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
    

    我做错什么了?

    N:B.尝试过

    • 使预期的批注具有构造函数[无成功]
    • 使所需的批注与构造函数匹配[错误:参数'{0}'在所需批注和实际批注中有冲突的值]

    仅供参考:我的build.gradle已经有了noarg,因此user.kt类是用无参数公共构造函数编译的

    1 回复  |  直到 6 年前
        1
  •  0
  •   Kevin Galligan    6 年前

    expect注释可能需要显式括号。

    expect annotation class SharedImmutable()
    
    actual typealias SharedImmutable = kotlin.native.SharedImmutable
    

    https://github.com/touchlab/Stately/blob/4b17057ad5d55f51f4ccf971cf79e51585ad2324/src/commonMain/kotlin/co/touchlab/stately/annotation/Annotations.kt#L26

    推荐文章