I have two rectangles, one that is occasionally reset to some other rectangle. In C++ I'd just do:
_rect = _resetRect;
But in Dart that actually means that _rect
now refers to the same object as _resetRect
which is not what I want.
My current solution is this:
_rect.left = _resetRect.left;
_rect.width = _resetRect.width;
_rect.top = _resetRect.top;
_rect.height = _resetRect.height;
This is idiotic. Other questions suggest that there is no built-in way to copy objects (like there is in C++), and you have to rely on the object providing a clone()
method. But Rectangle
doesn't have one so what do I do?
Also even if it did have a clone()
method, wouldn't that allocate an entirely new Rectangle
rather than just setting the fields of the existing one (like C++'s operator=
), and therefore be less efficient?