Hullaballoonatic
12/01/2019, 3:56 AMdmitriy.novozhilov
12/01/2019, 6:31 AMinterface A {
val x: Int
get() = 1 // OK
val y: Int = 1 // Error
}
If you write val y = 1 you assume that y have backing field, but interfaces can't have state, so you can declare only custom getters/settersHullaballoonatic
12/01/2019, 6:59 AMHullaballoonatic
12/01/2019, 7:02 AMdmitriy.novozhilov
12/01/2019, 7:10 AMinterface Some {
int x = 1;
}
...
// prints 1
System.out.println(Some.x)dmitriy.novozhilov
12/01/2019, 7:12 AMlouiscad
12/01/2019, 9:02 AMconst val in the companion object of the interface.Hullaballoonatic
12/01/2019, 7:21 PMno state vs having a default state? (edit: yeah, gotcha. they already support default state via static field values)
@louiscad I actually am looking for default instance field values, not static ones, but thanks as that further illustrates the distinctionlouiscad
12/01/2019, 7:30 PMHullaballoonatic
12/01/2019, 7:37 PMlouiscad
12/01/2019, 7:40 PMHullaballoonatic
12/01/2019, 7:41 PM