![]() initial: R, operation: (index: Int, acc: R, T) -> R. The obvious downside to such a apprach is that I must not forget to change this class, in case i change User, something that looks very dangerous to me.īut I'm not sure how to do this. Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original collection and current accumulator value that starts with initial value. It seems to me that its is only available for static members and to what are primitives in Java and do not compile for class-variables: data class User(val name: String, val id: Int)įun getUser(): User ")Ĭonst val (name, id) = getUser() // does not compile eitherĪs this seems not to work, I think what i really want is a second class, that deletes the operations i don't want to support: class ConstUser : UserĬonstUser(var name: String, val id: int) : base(name, id) Note that MutableList is a list because it inherits from the List interface. It seems to very different to const in C++. List s are ‘read-only’, but they may or may not be mutable. It’s easy to come to the conclusion that the List type must therefore be immutable. ![]() ![]() But I don't think constants in kotlin are what I think they are. MutableList, as the name implies, is a list that has operations to mutate, or change, its contents: add, remove, and replace items.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |