I recently came across a presentation from EclipseCon 2014, where on page 5 they say "Lambda expressions allow you to treat code as data".
I also came across this example code
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("button clicked");
}
});
from "Java 8 Lambdas: Pragmatic Functional Programming" by Richard Warburton where he says
"This is actually an example of using code as data—we’re giving the button an object that represents an action."
What does code as data mean with respect to Lambda expressions and/or anonymous inner class?
Code consists of a compute capsule's source files, that means anything executable. Data are any files that the code operates on.
"Data" is the input or output of an application, and "code" is the set of instructions that specify what to do with the input. However, in most computer architectures, "code" and "data" are both just "stuff" in memory or on disk, and whether you consider any particular set of "stuff" as code or data is subjective.
The definition of coding is the process of creating instructions for computers using programming languages. Computer code is used to program the websites, apps, and other technologies we interact with every day.
For this reason, data are often coded. Coded allow the researcher to reduce large quantities of information into a form than can be more easily handled, especially by computer programs. Not all data need to be coded.
As you pass functionality as an argument to another method, such as what action should be taken when someone clicks a button like your example code.
Lambda expressions enable you to do this, to treat functionality as method argument = code as data.
See oracle linkfor more info and lambda code examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With