017-006-005

Functional Interface and Lambda

Hard

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:

  1. StringProcessor interface:

    • Add @FunctionalInterface annotation
    • String process(String input) - abstract method to process and return string
  2. Main class:

    • Create two StringProcessor instances using lambda expressions:
      • toUpperCase: converts input string to uppercase
      • addPrefix: adds "Processed: " before input string
    • Process "hello" with each processor and output results

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