1
// This example illustrates how C++ templates can be used from Java.
6
System.loadLibrary("example");
7
} catch (UnsatisfiedLinkError e) {
8
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);
13
public static void main(String argv[])
15
// Call some templated functions
16
System.out.println(example.maxint(3,7));
17
System.out.println(example.maxdouble(3.14,2.18));
21
vecint iv = new vecint(100);
22
vecdouble dv = new vecdouble(1000);
24
for (int i=0; i<100; i++)
27
for (int i=0; i<1000; i++)
28
dv.setitem(i, 1.0/(i+1));
32
for (int i=0; i<100; i++)
33
sum = sum + iv.getitem(i);
35
System.out.println(sum);
40
for (int i=0; i<1000; i++)
41
sum = sum + dv.getitem(i);
42
System.out.println(sum);