-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Copying simple objects #35309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this would be a natural part of the design of a 'value class' feature: We'd want to be able to create a copy of an existing value, except that the Would this be sufficient for your purposes, or would it be essential/helpful/convenient for that copy operation to work on mutable objects as well? (I'm sure we have an issue where 'value classes' or 'value types' are requested, but I can't find it right now; but the idea is that you get a concise notation for declaring a class where all fields are final; equality is implemented by code generation in the compiler as a deep comparison, recursively following all references that are themselves value types; and hashCode is generated correspondingly.) |
https://pub.dartlang.org/packages/built_value provides this currently via code generation |
@eernstg As long as the functionality exists, I personally do not care about the name. On that note, the naming convention in flutter for this would be |
I would appreciate if this was natively supported by the language. It makes it very convenient for value types. Its particularly useful on a Mixin (or trait), when you are providing code but you don't know the final type or will be applied to multiple types. The concrete type can't be referenced but one would be able to clone this and change the values on the cloned object. mixin AType on BType {
int usefulProperty;
BType increaseUsefulness() {
BType newObject = clone this;
newObject.usefulProperty = this.usefulProperty + 1;
return newObject;
}
} |
Is the dart-lang team willing to re-visit the idea of a dedicated
copy
function that allows users to create a deep or shallow copy of objects if it can be proven that there are no side effects (no setters present, etc.)?How about a dedicated copy constructor/operator similar to C++ for when such a copy cannot be done safely?
The last issue I could find was created/updated over 6/3 years ago: #3367
Dart 2.1.0 (build 2.1.0-dev.9.4 f9ebf21)
The text was updated successfully, but these errors were encountered: