StreamUnthrower

简介:Exception in lambda expressions
更多:作者   提 Bug   
标签:

Main thing - see class Unthrow.java

Lets you use checked exception in lambda expressions. One import and use!

import utils.stream.Unthrow;
...
    static class BlaBla {
        void method() throws IOException { ... }
        boolean isSomething() throws IOException { ... }
    }

    public void blablaDemo() {
        // :)
        getBlaBlaList().stream()
                .filter( blaBla -> Unthrow.wrap(() -> blaBla.isSomething()) )
                .forEach(blaBla -> Unthrow.wrapProc(() -> blaBla.method()) );
        // :(
        getBlaBlaList().stream()
                .filter( blaBla -> { try { return blaBla.isSomething(); } catch (Exception ex) { throw new RuntimeException(ex); } } )
                .forEach(blaBla -> { try { blaBla.method(); } catch (Exception ex) { throw new RuntimeException(ex); } } );
    }
...

Full Demo example of use.

Comparison examples of usage:

Features: -

  • it does not create new exceptions - re use existing
  • a minimum code
  • no substitution Stream, only the wrapper over the lambda

License

MIT

Free Software, Hell Yeah!

Android 开发经验分享
C 轮融资近 30 亿元理财推荐
Android 开发经验分享
C 轮融资近 30 亿元理财推荐