Hi all !
This message is not a help request neither another complaint post...
I just wanted to say that I'm happy to see that Android seems to
perfectly implement the JDK Proxy/InvocationHandler API... And that's
great !
Ok, maybe some people already knew this. But I didn't, so I'm glad to
share ;-) .
For those wondering "what the hell is he talking about ?", quick usage
example :
public interface IUserService {
void getSomeData(String param);
}
[...]
ClassLoader cl = IUserService.class.getClassLoader();
InvocationHandler h = new InvocationHandler() {
public Object invoke(Object proxy, Method m, Object[] args) throws
Throwable {
System.out.println(m);
System.out.println(args[0]);
return null;
}
};
IUserService service = (IUserService) Proxy.newProxyInstance(cl, new
Class[] {IUserService.class}, h);
Calling :
service.getSomeData("yeah!");
will print the method signature and the argument...
I now use interfaces + annotations to define my JSON client services,
no more boiler plate code, I love it :-) .
Who said AOP is not for Android ? :-) . Of course, there is still no
dynamic byte-code creation, but that's cool enough.
And I don't wanna hear about any performance concern :-) . It all
depends on what you're doing. For instance, when dealing with getting
data from the internet, what is the relative cost of a proxy ? Not
much... Of course, one should not use this in the graphical components
of a 3D game...
Cheers,
Piwai
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en