You need to enable JavaScript to run this app. Kotlin接口伴生对象@JvmOverloads触发ClassFormatError编译错误
优惠活动
大模型
产品
解决方案
定价
更多

Kotlin接口伴生对象@JvmOverloads触发ClassFormatError编译错误

Kotlin接口伴生对象使用@JvmOverloads的编译异常

在Kotlin开发场景中,为接口的伴生对象函数添加@JvmOverloads注解时,即便同时搭配使用@JvmStatic注解,也会触发编译流程的类格式错误,复现代码如下:

interface Foo {
    companion object {
        @JvmStatic
        @JvmOverloads
        fun bar(a: Int = 1, b: Int = 2){}
    }
}

代码编写阶段在IntelliJ IDEA中开发时,IDE不会给出任何错误提示,但执行实际编译流程时,会抛出如下类格式异常:

Method bar in class Foo has illegal modifiers: 0x19
java.lang.ClassFormatError: Method bar in class Foo has illegal modifiers: 0x19

该问题属于Kotlin编译器的已知缺陷,对应修复已在Kotlin 1.4.20版本中正式发布。

内容的提问来源于stack exchange,提问作者FredSuvn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.19 13:36:08