PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-26/SWIG/Examples/java/constants/main.java

#
Java | 44 lines | 39 code | 4 blank | 1 comment | 0 complexity | 85edcbfaf50a2850ba560d2cf2a60b41 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. import java.lang.reflect.*;
  2. public class main {
  3. static {
  4. try {
  5. System.loadLibrary("example");
  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. System.out.println("ICONST = " + example.ICONST + " (should be 42)");
  14. System.out.println("FCONST = " + example.FCONST + " (should be 2.1828)");
  15. System.out.println("CCONST = " + example.CCONST + " (should be 'x')");
  16. System.out.println("CCONST2 = " + example.CCONST2 + " (this should be on a new line)");
  17. System.out.println("SCONST = " + example.SCONST + " (should be 'Hello World')");
  18. System.out.println("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')");
  19. System.out.println("EXPR = " + example.EXPR + " (should be 48.5484)");
  20. System.out.println("iconst = " + example.iconst + " (should be 37)");
  21. System.out.println("fconst = " + example.fconst + " (should be 3.14)");
  22. // Use reflection to check if these variables are defined:
  23. try
  24. {
  25. System.out.println("EXTERN = " + example.class.getField("EXTERN") + " (Arg! This shouldn't print anything)");
  26. }
  27. catch (NoSuchFieldException e)
  28. {
  29. System.out.println("EXTERN isn't defined (good)");
  30. }
  31. try
  32. {
  33. System.out.println("FOO = " + example.class.getField("FOO") + " (Arg! This shouldn't print anything)");
  34. }
  35. catch (NoSuchFieldException e)
  36. {
  37. System.out.println("FOO isn't defined (good)");
  38. }
  39. }
  40. }