Closed lgcat76 closed 1 year ago
I think the original intent was to provide clear feedback if the developer made an error and set a constraint on an element that already had a constraint.
I'm a little reluctant to eliminate that helpful feedback and just silently "use the last set constraint" which might be a lot harder to debug if you did not understand what was going on. As you say, if you do mean to change the constraint you can call setConstraint(null)
followed by setConstraint(newConstraint)
.
However, the fact that it does not fail if assertions are not enabled is definitely dangerous and misleading as well. So maybe just noting in the Javadoc that setConstraint replaces any previously configure constraint is warning enough and hopefully no one will shoot themselves in the foot.
There seems to be some legitimate use cases for changing constraints. For example, when using AbsoluteLayout, different instances of AbsoluteLayout.Constraint may be used, to change the location of absolutely positioned elements.
Besides, the check could be easily worked around by calling setConstraint(null) before setting the new constraint, so it wasn't specially effective.
This would solve #96.