Define
a Functional interface that returns a boolean value.
Application.java
BooleanProvider.java
package com.sample.functional.interfaces; /** * Functional interface returns a boolean value. * * @author krishna * */ public interface BooleanProvider { /** * * @return a boolean value */ public boolean getAsBoolean(); }
Application.java
package com.sample.app; import com.sample.functional.interfaces.BooleanProvider; public class Application { private static void processInfo(BooleanProvider boolProvider) { if(boolProvider.getAsBoolean()) { System.out.println("Provider is returning true"); return; } System.out.println("Provider returning false"); } public static void main(String[] args) { processInfo(() -> true); processInfo(() -> false); } }
Output
Provider is returning true Provider returning false
No comments:
Post a Comment