开发者

Best way to make simple callback

开发者 https://www.devze.com 2023-03-07 07:48 出处:网络
I\'m in doubt of how works Java. I need do a code like it (in PHP): 开发者_运维技巧array_map(function($object){ ... });

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

精彩评论

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