Kotlin 中注解 @JvmOverloads 的作用

@JvmOverloads 注解的作用就是:在有默认参数值的方法加上 @JvmOverloads 注解,则 Kotlin 就会暴露多个重载方法。

例如,没有加注解,默认参数没有起到任何作用。

kotlin 复制代码
fun f(a: String, b: Int = 0, c: String = "abc") {

}

那相当于在 Java 中定义:

java 复制代码
void f(String a, int b, String c) {

}

如果加上注解 @JvmOverloads,默认参数起到作用:

kotlin 复制代码
fun f(a: String, b: Int = 0, c: String = "abc") {

}

// 相当于 Java 中
void f(String a)
void f(String a, int b)
void f(String a, int b, String c)
相关推荐
jimy117 分钟前
c++隐式移动构造、强制拷贝省略、返回具名局部变量
开发语言·c++
v_for_van31 分钟前
C语言__attribute__
服务器·c语言·开发语言·mcu·嵌入式·嵌入式实时数据库
mmsx40 分钟前
osmdroid 接入谷歌影像底图:瓦片 URL 拼接与多域名轮询实战
android·osmdroid
ZYJCSZKJ1 小时前
基于大语言模型的地域实体语义增强:生成式引擎优化(GEO)中的多模态内容生成实践
android·人工智能·语言模型
工业一体机老司机1 小时前
Python实现工业一体机Modbus-TCP通信-从协议解析到多设备轮询实战
开发语言·python·tcp/ip
ssshooter1 小时前
Tauri + GitHub Actions 自动化发布 Android APK 技术总结
android·github·android studio
fpcc1 小时前
跟我学C++中级篇—static_assert和assert
开发语言·c++
2401_885885041 小时前
国际语音php接口代码示例:PHP使用cURL快速调用语音发送API
android·开发语言·前端·人工智能·python·php·语音识别
萌动的小火苗1 小时前
Linux进程线程面试题【无答案】
linux·运维·服务器·c语言·开发语言
_李小白1 小时前
【Android UI开发】Android VideoView 使用介绍(一)
android·ui