Java Functional Interface: Runnable Example

You already know interfaces in Java. A Functional Interface is simply an interface with exactly one abstract method — nothing more. This constraint is intentional and it allows Java to represent behavior as a value. Runnable is a classic example. It defines a single contract: void run(); Because there is only one abstract method, the compiler can infer intent and accept a lambda as its implementation. Runnable task = () -> {   System.out.println("Executing task for Anwer Sayeed"); }; The lambda doesn’t replace Runnable. It implements its contract, concisely. This design choice is what enabled Java’s functional style without breaking its object-oriented foundations. #Java #FunctionalInterface #Runnable #LambdaExpressions #JavaDeveloper #CleanCode #Multithreading

To view or add a comment, sign in

Explore content categories