Kotlin没有看到Java Lombok访问器? [英] Kotlin doesn't see Java Lombok accessors?

查看:255
本文介绍了Kotlin没有看到Java Lombok访问器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Kotlin 1.0.0版本(在IntelliJ 15中编译).

Using Kotlin 1.0.0 release (compiling in IntelliJ 15).

println(myPojoInstance.foo)

当它尝试编译引用基于Lombok的POJO的代码(在IntelliJ或Gradle中)时,出现错误无法访问'foo':在"MyPojo"中为'private'.是的,它们都是私有的而且我的对象具有@Value @Builder用于lombok注释.

When it tries to compile code (in IntelliJ or Gradle) that references Lombok based POJOs it gives the error "Cannot access 'foo': it is 'private' in "MyPojo". Which is true, they're all private and my object has @Value @Builder for lombok annotations.

我已经尝试过专门调用getFoo(),但是它说未解析的getFoo引用".也许有一些技巧可以使Kotlin知道如何处理lombok注释?

I've tried specifically calling getFoo(), but it says "unresolved reference for getFoo". There's perhaps some trick to make Kotlin aware of how to handle the lombok annotations?

推荐答案

通常,不,不是.该行为的原因是Lombok是javac的注释处理器,但是当kotlin编译器运行时,它也使用javac但没有注释处理,因此这就是kotlin看不到尚未生成的声明的原因.

Generally, no, it doesn't. The reason of that behavior is that Lombok is an annotation processor for javac but when the kotlin compiler runs it uses javac as well but with no annotation processing so this is why kotlin don't see declarations that wasn't yet generated.

目前唯一的解决方法是定义严格的编译顺序:首先是Java,然后是kotlin.不幸的是,这种方法有很大的缺点:在这种情况下,您不能使用Java的Kotlin代码.要解决此问题,您可能需要多模块项目,这可能会导致很多痛苦

The only workaround for now is to define strict compilation order: Java first and after that kotlin. Unfortunately this approach has great disadvantage: you can't use Kotlin code from Java in this case. To workaround it you may need multimodule project that may cause a lot of pain

这篇关于Kotlin没有看到Java Lombok访问器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆