Trevor Hackman
Nov 16, 2023

--

In Kotlin you can do the following:

```

data class Train(val name: String, private val _stations: List<String>) {

val stations = _stations.toList()

}

```

I'm not sure it's the exact same as the Java Record still, but we have an immutable stations list and still kept the class a data class.

--

--

Trevor Hackman
Trevor Hackman

Written by Trevor Hackman

Hi, I am an Android developer.

Responses (1)