gpt4 book ai didi

constructor - 类主构造函数的 JvmOverloads 注释

转载 作者:IT老高 更新时间:2023-10-28 13:29:29 27 4
gpt4 key购买 nike

为什么禁止从具有默认参数的类主构造函数自动生成许多对 Java 可见的构造函数?

@JvmOverloads
class Video(private val id: Long, val ownerId: Long, var title: String? = null, var imgLink: String? = null, var videoLink: String? = null,
var description: String? = null, var created: Date? = null, var accessKey: String? = null, var duration: Long? = null,
var views: Long? = null, var comments: Long? = null) : Entity

This annotation is not applicable to target 'class'

最佳答案

这不是禁止的,您只是将 @JvmOverloads 应用于错误的目标。注释主构造函数的正确方法是在 @JvmOverloads 之前显式指定 constructor 关键字:

class Video @JvmOverloads constructor(
private val id: Long,
val ownerId: Long,
var title: String? = null,
var imgLink: String? = null,
var videoLink: String? = null,
var description: String? = null,
var created: Date? = null,
var accessKey: String? = null,
var duration: Long? = null,
var views: Long? = null,
var comments: Long? = null
) : Entity

关于constructor - 类主构造函数的 JvmOverloads 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35748906/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com