java - Reuse static method for Function mapping -
using play, controller class has several methods pattern:
public static promise<result> getfoo() { promise<response> resp = ws.url("/api/foo").get(); return resp.map(new function<response, result>() { @override public result apply(response arg0) throws throwable { string body = arg0.getbody(); return results.ok(body); } }); } i considered creating seperate mapping function:
private static function<response, result> mapresponse = new function<response, result>() { @override public result apply(response arg0) throws throwable { string body = arg0.getbody(); return results.ok(body); } }; so can reuse in multiple static methods:
public static promise<result> getfoo() { promise<response> resp = ws.url("/api/foo").get(); return resp.map(mapresponse); } public static promise<result> getbar() { promise<response> resp = ws.url("/api/bar").get(); return resp.map(mapresponse); } intuitively think may cause problems multiple methods reusing same static mapping method, realized not sure of actual behavior. wondering if reusing static variable bottleneck concurrent calls, or jvm automatically instantiate multiple copies handle processing in different methods.
what drawbacks of such approach, or work properly? if not, options reduce boilerplate mapping code used in multiple methods?
note: don't think question above specific play more of generic java coding question, hence not using play tag.
Comments
Post a Comment