2013年7月28日 星期日

function pointer usage in Android/Java

Java does not support function pointer assignment, but there's an alternative to achieve the similar goal:

interface JS2ANRD_Prototype {
        public Element getElementById();
        public Element getElementsByTagName();

}

 kkk(new JS2ANRD_Prototype() {
            public Element getElementById() {
                return (Element)null;
            }
            public Element getElementsByTagName() {
                return (Element)null;
            }
        });


public void kkk(JS2ANRD_Prototype p) {...}

Reference links
http://www.ozzysun.com/2011/07/androidcallback.html
http://stackoverflow.com/questions/1073358/function-pointers-in-java

沒有留言:

張貼留言