def __instancecheck__(self, inst): """Called to check if an object is an instance of this class. """ if isinstance(inst, _JavaObject): return _pyjava.issubclass( inst.__dict__['_pyjava_class'].__dict__['_pyjava_javaclass'], self.__dict__['_pyjava_javaclass']) else: return False
def test_issubclass(self): """Requests well-known classes and tests issubclass(). """ Object = _pyjava.getclass('java/lang/Object') String = _pyjava.getclass('java/lang/String') Class = _pyjava.getclass('java/lang/Class') self.assertTrue(_pyjava.issubclass(String, String)) self.assertTrue(_pyjava.issubclass(Object, Object)) self.assertTrue(_pyjava.issubclass(Class, Class)) self.assertFalse(_pyjava.issubclass(Object, String)) self.assertFalse(_pyjava.issubclass(String, Class)) self.assertTrue(_pyjava.issubclass(Class, Object)) self.assertFalse(_pyjava.issubclass(Class, String)) self.assertTrue(_pyjava.issubclass(String, Object)) self.assertFalse(_pyjava.issubclass(Object, Class))
def __subclasscheck__(self, other): """Called to check if a class is a subclass of this class """ if isinstance(other, _JavaClass): return _pyjava.issubclass(other.__dict__['_pyjava_javaclass'], self.__dict__['_pyjava_javaclass']) elif isinstance(other, type): # A non-Java class return False else: # Not a class raise TypeError("issubclass() arg 2 must be a class")