/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
1import java.lang.reflect.*; 2 3public class main { 4 static { 5 try { 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); 9 System.exit(1); 10 } 11 } 12 13 public static void main(String argv[]) 14 { 15 System.out.println("ICONST = " + example.ICONST + " (should be 42)"); 16 System.out.println("FCONST = " + example.FCONST + " (should be 2.1828)"); 17 System.out.println("CCONST = " + example.CCONST + " (should be 'x')"); 18 System.out.println("CCONST2 = " + example.CCONST2 + " (this should be on a new line)"); 19 System.out.println("SCONST = " + example.SCONST + " (should be 'Hello World')"); 20 System.out.println("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')"); 21 System.out.println("EXPR = " + example.EXPR + " (should be 48.5484)"); 22 System.out.println("iconst = " + example.iconst + " (should be 37)"); 23 System.out.println("fconst = " + example.fconst + " (should be 3.14)"); 24 25// Use reflection to check if these variables are defined: 26 try 27 { 28 System.out.println("EXTERN = " + example.class.getField("EXTERN") + " (Arg! This shouldn't print anything)"); 29 } 30 catch (NoSuchFieldException e) 31 { 32 System.out.println("EXTERN isn't defined (good)"); 33 } 34 35 try 36 { 37 System.out.println("FOO = " + example.class.getField("FOO") + " (Arg! This shouldn't print anything)"); 38 } 39 catch (NoSuchFieldException e) 40 { 41 System.out.println("FOO isn't defined (good)"); 42 } 43 } 44}