4.9 - Functional Interfaces & Java Lambda Expressions

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What are the 4(+) key concepts of OOP?

1. Encapsulation 2. Inheritance 3. Abstraction 4. Polymorphism (5. Composition)

What is a "Functional Interface"?

A Functional Interface is any interface with exactly 1 abstract method

What are the FOUR functional interfaces we used in reading/prework/classwork? (in depth after t his

Function: Supplier Consumer Predicate

What do we call the methods that are in Interfaces? Why?

We call them abstract. Because within the Interface, the behavior is not defined. Classes implement interfaces, and within those Classes, the behavior is defined. The Interface is just the contract.

What does the Function lambda expression do?

Accepts an object and returns an object

What does the Predicate lambda expression do?

Accepts an object, returns Boolean

What does the Consumer lambda expression do?

Accepts an object, returns nothing (void) Consumers are commonly used when performing an operation on each member of a data structure, or updating another data structure by calling the Consumer on each element.

What does the Supplier lambda expression do?

Accepts no parameters, returns an object

What's an anonymous method? What's an example of one?

An anonymous method is a method without a formal method declaration. Lambda expressions are one example of an anonymous method.

Scope of Lambda Expressions, how do you give a lambda expression "class scope" and what does that mean?

Class scope means that any method in the class has access to it. In order to get that, you need to define the lambda expression at the top of the class and assign it to a variable.

What is an interface? What's an example of an interface?

Interfaces are "contracts" that define how a class should behave. An interface's method signatures define the behaviors. List<E> is an example of an interface

If you define a lambda expression in a block of code (curly braces), what scope does it have, and what does that mean?

It will have block scope. It means it can only be used in that specific block of code. If you define a Lambda Expression inside parentheses as a parameter to a method call, it will only have scope in the block of code executing that method.

What's more common for Lambda Expressions, defining them in the class header and giving them a variable, or defining them within a single block of code (either in the arguments, or in the block)?

It's way more common to define a Lambda Expression in a single method call.

Do we have to write our own Functional Interfaces or does Java provide any? What would examples be?

Java provides some very useful Functional Interfaces already. A couple examples are Function, Supplier, Predicate, and Consumer. These are called Standard Java Functional Interfaces

Can generic parameters be primitives or objects?

No! They can only be objects, no primitives!

Reading Two: More functional interfaces with lambda expressions https://code.amazon.com/packages/ATACurriculum_LearningMaterials/blobs/mainline/--/lambda_expressions/02_more_functional_interfaces_with_lambda_expressions.md

Reading Two: More functional interfaces with lambda expressions https://code.amazon.com/packages/ATACurriculum_LearningMaterials/blobs/mainline/--/lambda_expressions/02_more_functional_interfaces_with_lambda_expressions.md

SYNTAX KEYWORD

The reading explanations are poor. Here's good info https://beginnersbook.com/2017/10/java-lambda-expressions-tutorial-with-examples/#:~:text=Java%20Lambda%20Expression%20Syntax,right%20side%20of%20lambda%20operator.


Set pelajaran terkait

Chapter 14: The Family, the State, and Social Policy

View Set

Combo with E-Commerce and 2 others

View Set

Chapter 46: Management of Patients with Diabetes

View Set

Mesoamerica, Atlantic Slave Trade and European Colonization

View Set

6.4.5 Intrusion Detection and Prevention

View Set