https://kotlinlang.org logo
#codereview
Title
# codereview
b

bob

03/06/2017, 9:11 PM
@Andreas Sinz Okey, what would you suggest as a good workaround since I do work in a mixed java-kotlin project and have a lot of interfaces in java that I have to implement in kotlin, and this problem occurs from time to time.
a

Andreas Sinz

03/06/2017, 9:17 PM
bob: you could override the method as always and use a private val behind the scene
Copy code
fun main(args: Array<String>) {
 	val bar = Bar()
    
    println(bar.getId())    
}

interface Foo {
    fun getId(): Int
}

class Bar : Foo {
    override fun getId(): Int {
        return id
    }
    
    private val id: Int = 5
}
b

bob

03/06/2017, 9:33 PM
Okey, so thats the recommended solution. It’s a bit verbose to be kotlin 😉