开发者

Best way to make simple callback

I'm in doubt of how works Java. I need do a code like it (in PHP):

开发者_运维技巧array_map(function($object){ ... });

And on Java, I close to it:

this.addTransition(new CallerTransition() {
    @Override
    protected void execute() {
        // Do something with _this_ here
    }
});

Translating: I need know if exists a better way to work with closures-like.

Notes: CallerTransition is subtyped Transition. addTransition requires a Transition. The execute method will be executed by addTransition.


Java doesn't have lambda functions or function-based closures, so I'm afraid anonymous classes are the best way to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜