swig/Examples/test-suite/java/virtual_poly_runme.java
Marcelo Matus 394aacb890 using static narrow methods instead of %extended ones.
now it looks more natural and similar to the CORBA downcasting mechanism.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5587 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-12-23 10:10:04 +00:00

48 lines
1.2 KiB
Java

// virtual_poly test
import virtual_poly.*;
public class virtual_poly_runme {
static {
try {
System.loadLibrary("virtual_poly");
} catch (UnsatisfiedLinkError e) {
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);
System.exit(1);
}
}
public static void main(String argv[]) {
NDouble d = new NDouble(3.5);
NInt i = new NInt(2);
NInt j = virtual_poly.incr(i);
//
// These two natural 'copy' forms fail, only java and csharp
// because no polymorphic return types are supported.
// But we can live with this restriction, more or less.
//
// NDouble dc = d.copy();
// NInt ic = i.copy();
//
// These two 'copy' forms work, but we end with plain NNumbers
//
NNumber dc = d.copy();
NNumber ic = i.copy();
//
// The real problem is that there is no way to recover the
// original NInt or NDouble objects, even when you try to use the
// plain and natural C++ dynamic_cast operation, or the user
// downcasting mechanism:
//
// don't work
NDouble ddc = NDouble.narrow(dc);
NInt dic = NInt.narrow(ic);
}
}