An Approach to Use Java Lambda
Publication Date: 2017-May-01
The IP.com Prior Art Database
An Approach to use Java Lambda‐Values to Embed Executable Code in Expressions
Author: John McAlister A mechanism is disclosed that allows executable code to be used in places where only values are expected, using the “lambda‐expression” feature introduced in Java 8. Since lambda‐expressions can surround arbitrary blocks of code to compute the value they return, loops and other statements can be embedded in places where code would not normally reside. There are many examples where program execution requires an “expression” – this can be an actual value (e.g. 7, “May”, or a reference to a block of memory that holds some data), or some code that evaluates to a value (e.g. 1+1, “May ”+ “day”, or sqrt(4)). The problem is that code that evaluates to a value has been limited in functionality ‐ a number of code statements do not return a value, and thus cannot be used where an expression is required. One way to work around this limitation is to define the desired behavior in a function, and then call the function to determine the value for the expression. While this works, it introduces extra boilerplate overhead in Java (functions must be embedded in classes – there are no global functions, classes should be in packages, packages need to be imported), and sometimes is not possible in cases where external functions cannot be called. Java 8 introduced “lambda‐expressions”, which return values, and thus are expressions – but can surround any arbitrary collection of code. This results in the ability to place arbitrary blocks of code in any place that an expression can be used ‐ such as in a configuration file or a template...