I found recent interest in Kotlin as a language, because the platform we develop for is Java 6 based and hence lacks any syntactic sugar the recent years brought to Java.

只有一件事使得在开发中使用Kotlin而不是Java是不可能的,那就是我们开发的平台在内部使用了一些反射,并且要求成员是公开的.否则它不会起作用的.

So, the bytecode generated from the Kotlin file in fact produces public getters and setters, the fields themselves yet remain private.

Is there a way to overcome this, so I get real public fields?

我知道设计失败需要公共领域,但系统对我们来说是一个黑匣子,我们无法改变这样的事实.

推荐答案

The annotation @JvmField should help you. It makes the Kotlin-compiler expose the property as a field on the JVM. See here: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-field/

Kotlin相关问答推荐

这些Kotlin函数等效吗?

在KMP中使用koin将来自Android的上下文注入到SQLDelight Driver中

编译后的JavaFX应用程序立即以静默方式崩溃

如何在操作系统版本上正确获取Room数据库的路径>;=26 sdk?

如何更改默认推断没有接收者的函数类型?

为什么我的通用Kotlin函数中的这个转换未经判断?

Kotlin 可空泛型

基类中的 ViewModelProviders.get(...)

创建首选项屏幕时找不到androidx.preference.PreferenceScreen

如何在 android jetpack compose 中相互重叠列表项?

Kotlin 语言是如何用 Kotlin 编写的?

如何在 kotlin 的片段类中更改 ActionBar 标题?

从代码块执行和返回(在 Elvis 运算符之后)

未在IntelliJ IDEA上运行临时文件

任何处理器都无法识别以下选项:'[kapt.kotlin.generated, room.incremental]'

Kotlin中的Memoization功能

Kotlin:相互递归函数的尾部递归

尾随 lambda 语法(Kotlin)的目的是什么?

Kotlin 中的填充字符串

如何在 spring-boot Web 客户端中发送请求正文?