Search code examples
javastreambeanshellsailpoint

Does Beanshell supports java 8 streams?


When trying to execute below snippet where iterating values of Map<String,List> , it is throwing beanshell parse exception at symbol > . Any solution I could get to resolve this one?

map.entrySet().stream().forEach(map -> {
    if (map.getValue().stream().anyMatch(s -> groupDN.startsWith(s.toUpperCase()))) {
        return "DONE";
    }
    ;
});

Exception running rule: BeanShell script error: bsh.ParseException: Parse error at line 30, column 22. Encountered: > BSF info: Test_RO at line: 0 column: columnNo


Solution

  • Java 8+ Streams per se are actually "just" a bunch of Java library classes.

    What you are really asking here is whether BeanShell supports the following Java language features which are needed for writing idiomatic Java code that uses Streams:

    • generic types from Java 5,
    • lambdas and type inference from Java 8.

    As far as I can tell, the answer is "No" to all of those. Generic types are on the roadmap for BeanShell 3.0 (see https://github.com/beanshell/beanshell#development-road-map), but lambdas and type inference are not mentioned.


    If you want an interactive Java REPL that supports all of the Java language, you might do better looking at "jshell" which is part of standard Java SE from Java 9 onwards. Apparently it can be embedded ...