Functional Interface and Lambda
Problem Description
Functional Interface and Lambda
In this problem, you will create a program that defines a StringProcessor functional interface annotated with @FunctionalInterface, implements two processors using lambda expressions (one to convert a string to uppercase and one to prepend "Processed: "), and displays the results to standard output.
Learning Objective: Understand functional interfaces and implement them using lambda expressions
Overview
A functional interface is an interface with exactly one abstract method. It can be explicitly declared with @FunctionalInterface annotation and implemented concisely using lambda expressions.
Specifications
Complete the following interface and program:
StringProcessorinterface:- Add
@FunctionalInterfaceannotation String process(String input)- abstract method to process and return string
- Add
Mainclass:- Create two
StringProcessorinstances using lambda expressions:toUpperCase: converts input string to uppercaseaddPrefix: adds "Processed: " before input string
- Process "hello" with each processor and output results
- Create two
Implementation Hint
Basic lambda syntax: (parameters) -> { body }
Output Format
HELLO
Processed: hello
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up