Skip to content

Commit 79d5aff

Browse files
author
Stephen Cobbe
committed
Improved isEquals method.
1 parent 33f3655 commit 79d5aff

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

generator/java.stoneg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,8 @@ def generate_union_equals(self, data_type):
40984098
with w.block('public boolean equals(Object obj)'):
40994099
with w.block('if (obj == this)'):
41004100
w.out('return true;')
4101+
with w.block('if (obj == null)'):
4102+
w.out('return false;')
41014103
with w.block('else if (obj instanceof %s)', j.java_class(data_type)):
41024104
w.out('%s other = (%s) obj;', j.java_class(data_type), j.java_class(data_type))
41034105
with w.block('if (this._tag != other._tag)'):
@@ -4128,6 +4130,8 @@ def generate_struct_equals(self, data_type):
41284130
with w.block('public boolean equals(Object obj)'):
41294131
with w.block('if (obj == this)'):
41304132
w.out('return true;')
4133+
with w.block('if (obj == null)'):
4134+
w.out('return false;')
41314135
w.out('// be careful with inheritance')
41324136
with w.block('else if (obj.getClass().equals(this.getClass()))'):
41334137
w.out('%s other = (%s) obj;', j.java_class(data_type), j.java_class(data_type))

0 commit comments

Comments
 (0)