尝试创建ArrayList
players
的克隆。我想完全克隆它(ArrayList
包括它的内容)。
Activity.kt
lateinit var playersinfo: PlayersInfo
lateinit var players: ArrayList<Player>
lateinit var tempPlayers: ArrayList<Player>
override fun onCreate(savedInstanceState: Bundle?) {
val intent = intent
playersinfo = intent.getParcelableExtra<PlayersInfo>("playersinfo")
players = playersinfo.players
var tempPlayers: ArrayList<Player> = players.clone() // RETURNS ERROR
players.forEach { tempPlayers.add(it)}
Player.kt
@Parcelize
data class Player (
val name: String,
val age: Int,
val gender: String
): Parcelable
@Parcelize
class PlayersInfo(
val players: ArrayList<@RawValue Player>, val anyBelow18: Boolean = players.any { player -> player.age < 18 },
var location: String = "Other"
): Parcelable {
}
有什么问题吗?