首页 > 解决方案 > 如何使 Kotlin 的内联类构造函数对 groovy 可见?

问题描述

Kotlin 1.5 引入了值类,例如:

@JvmInline
value class ShopId(val raw: UUID)

在我的设置中,我有尝试创建这种类型的对象的常规测试:

new ShopId(TestData.SHOP_ID)

但是我收到一个错误:

  groovy.lang.GroovyRuntimeException: Could not find matching constructor for: domain.ShopId(UUID)

我猜错误与生成内联类签名的方式有关,根据文档

fun compute(x: UInt) will be represented as public final void compute-<hashcode>(int x)

因此,我尝试使用编译器 arg 更改修饰方案:

 -Xuse-14-inline-classes-mangling-scheme, 

可悲的是无济于事。

所以我的问题是:是否可以使用 groovy 中的 kotlin 内联类?如果是这样,我该怎么做?

标签: kotlingroovy

解决方案


推荐阅读