Beispiel #1
0
 def test_issameobject(self):
     """Tests for equality of references.
     """
     jcl = _pyjava.getclass(
             'pyjavatest/ObjFactory')
     makeObject = jcl.getmethod('makeObject')
     obj1 = makeObject.call(1)
     obj2 = makeObject.call(2)
     obj3 = makeObject.call(1)
     self.assertTrue(_pyjava.issameobject(obj1, obj1))
     self.assertTrue(_pyjava.issameobject(obj2, obj2))
     self.assertTrue(_pyjava.issameobject(obj3, obj3))
     self.assertFalse(_pyjava.issameobject(obj1, obj2))
     self.assertFalse(_pyjava.issameobject(obj2, obj3))
     self.assertTrue(_pyjava.issameobject(obj3, obj1))
     self.assertFalse(_pyjava.issameobject(obj2, obj1))
     self.assertFalse(_pyjava.issameobject(obj3, obj2))
     self.assertTrue(_pyjava.issameobject(obj1, obj3))
Beispiel #2
0
    def __eq__(self, other):
        """Tests that the two objects are the same.

        This tests equality is the Java sense, i.e. that the references are
        equal (Java has no operator overriding).
        In Java, its behaviors is similar to that of Python's "is" operator,
        but here we have to use == ("is" cannot be overridden).
        """
        if isinstance(other, _JavaObject):
            return _pyjava.issameobject(
                    other.__dict__['_pyjava_javaobject'],
                    self.__dict__['_pyjava_javaobject'])
        return False