source: java2python/src/test/java/testcode/ObjectFunctions.java@ 353

Last change on this file since 353 was 346, checked in by wouter, 2 years ago

version 0.1 of automatic java to python translator. Can translate some simple programs, lot of work remains to be done

File size: 1.0 KB
Line 
1package testcode;
2
3/**
4 * Basic object functions that have special translations: hashcode, equals,
5 * toString.
6 *
7 */
8public class ObjectFunctions {
9 private final int a;
10
11 public ObjectFunctions(int a) {
12 this.a = a;
13 }
14
15 @Override
16 public String toString() {
17 return Integer.toString(a); // aotoboxing not yet supported
18 }
19
20 @Override
21 public int hashCode() {
22 return a;
23 }
24
25 @Override
26 public boolean equals(Object obj) {
27 if (this == obj)
28 return true;
29 if (obj == null)
30 return false;
31 if (getClass() != obj.getClass())
32 return false;
33 ObjectFunctions other = (ObjectFunctions) obj;
34 return a == other.a;
35 }
36
37 public static void main(String[] args) {
38 // 'final' should be ignored as not supported in python.
39 final ObjectFunctions v = new ObjectFunctions(12);
40 ObjectFunctions v2 = new ObjectFunctions(12);
41 System.out.println(v.toString() + Boolean.toString(v.equals(v2))
42 + Integer.toString(v.hashCode()));
43 // 12True12 . We avoid autoboxing - not supported
44 // notice that in java this will print 12true12 -- LOWER CASE T.
45 }
46
47}
Note: See TracBrowser for help on using the repository browser.