From 7649f192157c2c7cd6f4d8f97cd45a0fd1e5caa5 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 8 Jun 2022 19:03:06 -0400 Subject: [PATCH] Add duck typing equals check to TextBox --- src/TextBox.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/TextBox.java b/src/TextBox.java index dea5ad9..8d9f4b6 100644 --- a/src/TextBox.java +++ b/src/TextBox.java @@ -56,6 +56,14 @@ public class TextBox extends Rectangle { @Override public boolean equals(Object o) { - return this == o; + try { + TextBox t = (TextBox)o; + // duck typing equals check + // if it shows the same id, assume that it is equal; this is because ids should be unique + // also makes some corner cases easier + return this.id.equals(t.id); + } catch (ClassCastException e) { + return false; + } } }