You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In section 10.2d of the notes, we want to model the above relationship, without violating referential integrity, and the following code is suggested:
public class Woman {
private Man boyfriend;
public void setBoyfriend(Man m) {
if (boyfriend == m) {
return;
}
if (boyfriend != null) {
boyfriend.breakUp();
}
boyfriend = m;
m.setGirlfriend(this); # Here
}
public void breakUp() {
boyfriend = null;
}
// ...
}
However, if null is passed into the setBoyfriend method, the last line of the method will throw a NullPointerException.
I believe changing it to the following will fix it:
if (m != null) {
m.setGirlfriend(this);
}
Similarly for the Man class
The text was updated successfully, but these errors were encountered:
papataco14
changed the title
W10.2d Enforcing referential integrity bug
W10.2d Enforcing referential integrity suggestion
Nov 8, 2023
In section 10.2d of the notes, we want to model the above relationship, without violating referential integrity, and the following code is suggested:
However, if
null
is passed into thesetBoyfriend
method, the last line of the method will throw aNullPointerException
.I believe changing it to the following will fix it:
Similarly for the
Man
classThe text was updated successfully, but these errors were encountered: