5 public class virtual_poly_runme {
9 System.loadLibrary("virtual_poly");
10 } catch (UnsatisfiedLinkError e) {
11 System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
16 public static void main(String argv[]) {
18 NDouble d = new NDouble(3.5);
22 // These two natural 'copy' forms fail because no covariant (polymorphic) return types
23 // are supported in Java.
25 // NDouble dc = d.copy();
26 // NInt ic = i.copy();
29 // Unlike C++, we have to downcast instead.
31 NDouble dc = (NDouble)d.copy();
32 NInt ic = (NInt)i.copy();
34 NDouble ddc = NDouble.narrow(dc);
35 NInt dic = NInt.narrow(ic);
37 virtual_poly.incr(ic);
38 if ( (i.get() + 1) != ic.get() )
39 throw new RuntimeException("incr test failed");
42 // Checking a pure user downcast
44 NNumber n1 = d.copy();
45 NNumber n2 = d.nnumber();
46 NDouble dn1 = NDouble.narrow(n1);
47 NDouble dn2 = NDouble.narrow(n2);
49 if ( (dn1.get()) != dn2.get() )
50 throw new RuntimeException("copy/narrow test failed");
53 // Checking the ref polymorphic case
55 NNumber nr = d.ref_this();
56 NDouble dr1 = NDouble.narrow(nr);
57 NDouble dr2 = (NDouble)d.ref_this();
58 if ( dr1.get() != dr2.get() )
59 throw new RuntimeException("copy/narrow test failed");