source: java2python/core/test/testcode/ObjectFunctions.py@ 481

Last change on this file since 481 was 473, checked in by wouter, 17 months ago

#126 Added CommentBlock to clean up the messy comment handling code.

File size: 905 bytes
Line 
1from typing import cast
2import sys
3from typing import List
4
5
6class ObjectFunctions:
7 '''
8 Basic object functions that have special translations: hashcode, equals,
9 toString.
10
11 '''
12 def __init__(self, a:int):
13 self.__a:int
14 self.__a=a
15 #Override
16 def __repr__(self) -> str:
17 # aotoboxing not yet supported
18 return str(self.__a)
19 #Override
20 def __hash__(self) -> int:
21 return self.__a
22 #Override
23 def __eq__(self,obj:type) -> bool:
24 if self is obj:
25 return True
26 if obj is None:
27 return False
28 if type(self) is not type(obj):
29 return False
30 other:ObjectFunctions = cast(ObjectFunctions,obj)
31 return self.__a is other.__a
32 @staticmethod
33 def main(args:List[str]) -> None:
34 v:ObjectFunctions = ObjectFunctions(12)
35 v2:ObjectFunctions = ObjectFunctions(12)
36 sys.stdout.write(str(v) + str(v.__eq__(v2)) + str(hash(v))+'\n')
37
38if __name__ == "__main__":
39 ObjectFunctions.main(sys.argv[1:])
Note: See TracBrowser for help on using the repository browser.