https://kotlinlang.org logo
Title
g

gildor

01/17/2018, 9:26 AM
There are no properties in Java, so it’s impossible there. You can have private getter and public setter methods, but not properties. It’s popular feature request https://youtrack.jetbrains.com/issue/KT-14663
a

arekolek

01/17/2018, 12:30 PM
I was thinking more of something like this:
public class Foo {
    private String bar;

    private String getBar() {
        return bar;
    }

    public void setBar(String bar) {
        this.bar = bar;
    }
}
But I was wrong, because you can’t use the property access syntax in Kotlin for this Java type.
But the fun part is that “convert to Kotlin” breaks on this code
It produces
class Foo {
    private var bar: String? = null
        set
}
and changes the usage to:
var foo = Foo()
foo.bar = "dsfafdas"
from
foo.setBar("dsfafdas")
i

igor.wojda

01/24/2018, 4:29 PM
I like the idea