diff --git a/jnius/__init__.py b/jnius/__init__.py index 8ac24eb..34c2599 100644 --- a/jnius/__init__.py +++ b/jnius/__init__.py @@ -15,15 +15,17 @@ from .reflect import * # XXX monkey patch methods that cannot be in cython. # Cython doesn't allow to set new attribute on methods it compiled +HASHCODE_MAX = 2 ** 31 - 1 + class PythonJavaClass_(PythonJavaClass): @java_method('()I', name='hashCode') def hashCode(self): - return id(self) + return id(self) % HASHCODE_MAX @java_method('()Ljava/lang/String;', name='hashCode') def hashCode_(self): - return '{}'.format(id(self)) + return '{}'.format(self.hashCode()) @java_method('()Ljava/lang/String;', name='toString') def toString(self):