/trunk/Examples/test-suite/java/dynamic_cast_runme.java

# · Java · 29 lines · 23 code · 5 blank · 1 comment · 1 complexity · 17fa43cb3704e0d687302aeaf9dbb465 MD5 · raw file

  1. import dynamic_cast.*;
  2. public class dynamic_cast_runme {
  3. static {
  4. try {
  5. System.loadLibrary("dynamic_cast");
  6. } catch (UnsatisfiedLinkError e) {
  7. 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);
  8. System.exit(1);
  9. }
  10. }
  11. public static void main(String argv[])
  12. {
  13. Foo f = new Foo();
  14. Bar b = new Bar();
  15. Foo x = f.blah();
  16. Foo y = b.blah();
  17. // Note it is possible to downcast y with a Java cast.
  18. String a = dynamic_cast.do_test((Bar)y);
  19. if (!a.equals("Bar::test")) {
  20. System.err.println("Failed!");
  21. System.exit(1);
  22. }
  23. }
  24. }