swig/Examples/test-suite/java/virtual_poly_runme.java
Marcelo Matus 8c7824b76e fix bad variable name in example
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5583 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2003-12-22 06:32:02 +00:00

44 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);
//
// 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 operations,
// since they fail:
//
NDouble ddc = virtual_poly.NDouble_dynamic_cast(dc);
NInt dic = virtual_poly.NInt_dynamic_cast(ic);
}
}