Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Code as Data" mean?

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?

like image 941
SDS Avatar asked Feb 01 '15 19:02

SDS


People also ask

What is difference code and data?

Code consists of a compute capsule's source files, that means anything executable. Data are any files that the code operates on.

Are codes considered data?

"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.

What does it mean to code on the Internet?

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.

Why is data sometimes coded?

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.


1 Answers

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.

like image 77
MrSimpleMind Avatar answered Oct 30 '22 16:10

MrSimpleMind