This happens in a Java and maven project in Eclipse with a kotlin nature.
In this part of the code:
val faces = figure.getFaces()
for (polygon in faces) {
//...
I get the error below in eclipse, where faces
, in the second line above, is underlined in red:
Cannot access class 'Polygon'. Check your module classpath for missing or conflicting dependencies
The project is a mix of Java and Kotlin. The figure
object is an instance of a Java class, while the faces
are a set of type Polygon
which is in a different project that is pure Kotlin (ie Polygon
is a Kotlin type, in a separate Kotlin project).
This Kotlin project where Polygon
is, is indeed in the classpath as a Maven dependency, and in fact used by the Java class of which figure
is an instance.
I think the problem is in Eclipse, because I can build the project with maven successfully. It looks like either a bug in eclipse or a configuration issue.
I know it's strange to have a mix of Java and Kotlin. I simply started this project in Java and then decided to convert it to Kotlin gradually. So far I haven't had many issues but I'm aware that Kotlin tools and support in eclipse are not mature yet.
Not much of a proper solution: I converted my Figure
class to Kotlin and the problem went away, but I can do that because I have full control on my project.
Possibly newer versions of the eclipse plugin won't generate this error or, as suggested in the comments, switching to IntelliJ IDEA is another option.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.