5

I'm trying Vert.x in Kotlin. I have the following piece of code:

val deploymentOptions = DeploymentOptions()
deploymentOptions.setConfig(JsonObject().put("http.port", 8081))

Everything works fine. However, IntelliJ IDEA reports on the second line that I should use "Kotlin synthetic properties".

Any idea how to do that in this case. Also, I'm using Maven.

0

2 Answers 2

9

Hit alt+enter on that line. IDEA should suggest you a solution. Pick one.

Probably:

deploymentOptions.config = JsonObject().put("http.port", 8081)

4

In Kotlin documentation for Java interop, it talks about getters and setters and how they relate to properties:

Methods that follow the Java conventions for getters and setters (no-argument methods with names starting with get and single-argument methods with names starting with set) are represented as properties in Kotlin.

And it provides the example:

import java.util.Calendar

fun calendarDemo() {
    val calendar = Calendar.getInstance()
    if (calendar.firstDayOfWeek == Calendar.SUNDAY) {  // call getFirstDayOfWeek()
        calendar.firstDayOfWeek = Calendar.MONDAY       // call setFirstDayOfWeek()
    }
}

The tip you are receiving in your IDE is telling you that it is better (idiomatic) to use the property syntax instead of calling a getter or setter directly. Therefore instead of using:

deploymentOptions.setConfig(...)

You would use:

deploymentOptions.config = ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.