I sometimes want to create getters of immutable ve...
# codereview
e
I sometimes want to create getters of immutable versions of properties. Is there a better way than having two properties with different names?
e
better to use one of
Copy code
val textToPrint: List<String>
    get() = text
val textToPrint: List<String>
    get() = text.toList()
explicit cast might be between types that fail at runtime. implicit cast (as in 1) is always something that can succeed, according to the type system. or creating a defensive copy (as in 2) prevents the caller from casting back to mutable and gaining inappropriate access to your private data