Hi, I'm following the Udacity bootcamp and one of ...
# getting-started
d
Hi, I'm following the Udacity bootcamp and one of the examples in the lecture doesn't work for me, this is the code:
Copy code
package aquarium

class Aquarium (var length: Int, var width: Int, var height: Int) {

    var volume: Int
        get() = width * height * length / 1000
        set(value) = {height = (value * 1000) / (width * length)}
This is the warning I'm getting from Intellij for the set(value):
Copy code
Type mismatch: inferred type is () -> Unit but Unit was expected
I don't understand what is this supposed to signify?
r
You need to remove the
=
after
set(value)
👍 2
z
You need to remove the the
=
in
set(value) = { ... }
otherwise you are indicating that the setter is returning a lambda. The
Type mismatch: inferred type is () -> Unit but Unit was expected
is indicating that by stating that the compiler is expecting a
Unit
type but is finding
() -> Unit
as type. Remember that a
{
starts a block and that
}
ends a block, and assigning a block is creating a lambda. I make that mistake a lot too, even after working with kotlin for years. 😅
👍 4