Supplier |
Accounts.java
@FunctionalInterface public interface Accounts{ abstract String showAccountType(); } AccountImpl.java public class AccountImpl { public static void main(String[] args) { //Implementation of Custom Supplier Method for Accounts Interface Accounts squareRoot = () -> "Hi there"; System.out.println(squareRoot.showAccountType()); } } The above code could be expanded as below using Anonymous Inner Class public class AccountImpl { public static void main(String[] args) { Accounts squareRoot = new Accounts() { @Override public String showAccountType() { return "Hi there"; } }; System.out.println(squareRoot.showAccountType()); } } |
Consumer |
Accounts.java
@FunctionalInterface public interface Accounts { abstract void showAccountType(String strAccType); } AccountImpl.java public class AccountImpl { public static void main(String[] args) { //Implementation of Custom Consumer Method for Accounts Interface Accounts squareRoot = (strAccType) -> System.out.println(strAccType); squareRoot.showAccountType("Savings"); } } The above code could be expanded as below using Anonymous Inner Class public class AccountImpl { public static void main(String[] args) { Accounts squareRoot = new Accounts() { @Override public void showAccountType(String strAccType) { System.out.println(strAccType); } }; } } |
Predicate |
Accounts.java
@FunctionalInterface public interface Accounts{ abstract boolean showAccountType(String accountType); } AccountImpl.java public class AccountImpl { public static void main(String[] args) { //Implementation of Custom Predicate Method for Accounts Interface Accounts squareRoot = (accountType) -> { if ("Savings" == accountType) return true; else return false; }; if (squareRoot.showAccountType("Savings")) System.out.println("Savings"); else System.out.println("Invalid Account"); } } The above code could be expanded as below using Anonymous Inner Class public class AccountImpl { public static void main(String[] args) { Accounts squareRoot = new Accounts() { @Override public boolean showAccountType(String accountType) { if ("Savings" == accountType) return true; else return false; } }; if (squareRoot.showAccountType("Savings")) System.out.println("Savings"); else System.out.println("Invalid Account"); } } |
Function |
Accounts.java
@FunctionalInterface public interface Accounts { abstract String showAccountType(String accountType, String returnAccType); } AccountImpl.java public class AccountImpl { public static void main(String[] args) { //Implementation of Custom Function Method for Accounts Interface Accounts squareRoot = (accountType, returnType) -> { if (accountType == "Savings") return "Credit"; else return "Debit"; }; System.out.println(squareRoot.showAccountType("Savings", null)); } } The above code could be expanded as below using Anonymous Inner Class public class AccountImpl { public static void main(String[] args) { Accounts squareRoot = new Accounts() { @Override public String showAccountType(String accountType, String returnAccType) { if (accountType == "Savings") return "Credit"; else return "Debit"; } }; System.out.println(squareRoot.showAccountType("Savings", null)); } } |
Urnary Operator |
Accounts.java
@FunctionalInterface public interface Accounts{ abstract String showAccountType(String accountType); } AccountImpl.java public class AccountImpl { public static void main(String[] args) { //Implementation of Custom Operator Method for Accounts Interface Accounts squareRoot = (accountType) -> { return "AccountType is " + accountType; }; squareRoot.showAccountType("Savings"); } } The above code could be expanded as below using Anonymous Inner Class public class AccountImpl { public static void main(String[] args) { Accounts squareRoot = new Accounts() { @Override public String showAccountType(String accountType) { return "AccountType is " + accountType; } }; System.out.println(squareRoot.showAccountType("Savings")); } } |