Does this return a new map everytime it's read? ``...
# android
l
Does this return a new map everytime it's read?
Copy code
interface Foo {
    val bar: Map<String, String>
        get() = mapOf("1" to "1")
}
I would say yes but not sure
👌 3
r
Yes
👍 2
r
As a side note, if you want it to not return a new map every time it's read, you can use the
lazy
delegate:
Copy code
val bar: Map<String, String>
  by lazy {
    mapOf("1" to "1")
  }
l
Oh nice, thanks @Russell Stewart
r
No problem!
l
@Russell Stewart I get
Delegated properties are not allowed in interfaces
r
Oh, right. Sorry. My mistake; I forgot that it's an interface.
l
I guess you have overseen the interface
Alright
g
You can cache map in a top level property (outside of the interface)
👍 2
c
val bar = mapOf("1" to "1")