“Good” method to call method on each object using Stream API

后端 未结 3 1373
长情又很酷
长情又很酷 2021-02-12 06:14

Is it possible to run a method, in a consumer, like a method reference, but on the object passed to the consumer:

Arrays.stream(log.getHandlers()).forEach(h ->         


        
3条回答
  •  心在旅途
    2021-02-12 06:47

    I suppose it should be:

    Arrays.stream(log.getHandlers()).forEach(Handler::close);
    

    Provided the log.getHandlers() returns an array of objects of type Handler.

提交回复
热议问题