How to compile / load lambda expression dynamically in JDK8?

I would like to get an instance of a functional interface, for example. Predicate from a string. For example, user types of lambda expressions in the text field of the user interface for filtering some list of numbers list.stream (). filter ("lambda here")

+4
source share
1 answer

There is no direct way to do this. I'm afraid Java has not turned into some kind of dynamic language.

You can use the Java Compiler API that exists with JDK6 to compile a piece of code into a class that implements Predicate and loads it on the fly, but it will not.

+5
source

Source: https://habr.com/ru/post/1486766/


All Articles