KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > NativeCallBack


1 import proguard.annotation.*;
2
3 /**
4  * This application illustrates the use of annotations for configuring ProGuard.
5  *
6  * After having been compiled, it can be processed using:
7  * java -jar proguard.jar @examples.pro
8  *
9  * The annotation will preserve the class and its main method.
10  */

11 @KeepApplication
12 public class NativeCallBack
13 {
14     /**
15      * Suppose this is a native method that computes an answer.
16      *
17      * The -keep option regular ProGuard configuration will make sure it is
18      * not renamed when processing this code.
19      */

20     public native int computeAnswer();
21
22
23     /**
24      * Suppose this method is called back from the above native method.
25      *
26      * ProGuard would remove it, because it is not referenced from java.
27      * The annotation will make sure it is preserved anyhow.
28      */

29     @Keep
30     public int getAnswer()
31     {
32         return 42;
33     }
34
35
36     public static void main(String JavaDoc[] args)
37     {
38         int answer = new NativeCallBack().computeAnswer();
39
40         System.out.println("The answer is " + answer);
41     }
42 }
43
Popular Tags