0

私有 val 列表 = mutableListOf()

fun dataAddition() {
list.add(Feeds("1234", "Role.Driver", Message.Internal)
list.add(Feeds("1234", "Role.Supervisor", Message.Internal)
list.add(Feeds("1234", "Role.Idle", Message.Internal)
}

println(list)
Output expected:
Feeds("1234", "Role.Driver", Message.Internal), Feeds("1234", "Role.Supervisor", Message.Internal), Feeds("1234", "Role.Idle", Message.Internal)
But actual output received:
Message.Internal), Feeds("1234", "Role.Idle", Message.Internal),Message.Internal), Feeds("1234", "Role.Idle", Message.Internal),Message.Internal), Feeds("1234", "Role.Idle", Message.Internal)

如果您注意到它在列表中创建了一个新项目,但也修改了旧项目数据(例如:Role.Driver 被最后更新的值 Role.Idle 覆盖

4

0 回答 0