{"id":3146,"date":"2019-03-03T18:18:16","date_gmt":"2019-03-03T18:18:16","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3146"},"modified":"2021-05-15T09:11:48","modified_gmt":"2021-05-15T09:11:48","slug":"custom-functional-interface-definition-using-lamdas","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/custom-functional-interface-definition-using-lamdas\/","title":{"rendered":"Custom Functional Interface definition using Lamdas"},"content":{"rendered":"<table>\n<tr>\n<td><strong>Supplier<\/strong><\/td>\n<td>\n<strong>Accounts.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@FunctionalInterface\r\npublic interface Accounts{\r\n  abstract String showAccountType(); \r\n}\r\n<\/pre>\n<p><strong>AccountImpl.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  \/\/Implementation of Custom Supplier Method for Accounts Interface \r\n  Accounts squareRoot = () -&gt; &quot;Hi there&quot;;\r\n  System.out.println(squareRoot.showAccountType());\r\n }\r\n}\r\n<\/pre>\n<p>The above code could be expanded as below using Anonymous Inner Class<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  Accounts squareRoot = new Accounts() {\r\n   @Override\r\n   public String showAccountType() {\r\n    return &quot;Hi there&quot;;\r\n   }\r\n  };\r\n  System.out.println(squareRoot.showAccountType());\r\n }\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Consumer<\/strong><\/td>\n<td>\n<strong>Accounts.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@FunctionalInterface\r\npublic interface Accounts {\r\n abstract void showAccountType(String strAccType);\r\n}\r\n<\/pre>\n<p><strong>AccountImpl.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  \/\/Implementation of Custom Consumer Method for Accounts Interface\r\n  Accounts squareRoot = (strAccType) -&gt; System.out.println(strAccType);\r\n  squareRoot.showAccountType(&quot;Savings&quot;);\r\n }\r\n}\r\n<\/pre>\n<p>The above code could be expanded as below using Anonymous Inner Class<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  Accounts squareRoot = new Accounts() {\r\n   @Override\r\n   public void showAccountType(String strAccType) {\r\n    System.out.println(strAccType);\r\n   }\r\n  };\r\n }\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Predicate<\/strong><\/td>\n<td>\n<strong>Accounts.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@FunctionalInterface\r\npublic interface Accounts{\r\n  abstract boolean showAccountType(String accountType);\r\n}\r\n<\/pre>\n<p><strong>AccountImpl.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  \/\/Implementation of Custom Predicate Method for Accounts Interface\r\n  Accounts squareRoot = (accountType) -&gt; {\r\n   if (&quot;Savings&quot; == accountType)\r\n    return true;\r\n   else\r\n    return false;\r\n  };\r\n\r\n  if (squareRoot.showAccountType(&quot;Savings&quot;))\r\n   System.out.println(&quot;Savings&quot;);\r\n  else\r\n   System.out.println(&quot;Invalid Account&quot;);\r\n }\r\n}\r\n<\/pre>\n<p>The above code could be expanded as below using Anonymous Inner Class<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  Accounts squareRoot = new Accounts() {\r\n   @Override\r\n   public boolean showAccountType(String accountType) {\r\n    if (&quot;Savings&quot; == accountType)\r\n     return true;\r\n    else\r\n     return false;\r\n   }\r\n  };\r\n\r\n  if (squareRoot.showAccountType(&quot;Savings&quot;))\r\n   System.out.println(&quot;Savings&quot;);\r\n  else\r\n   System.out.println(&quot;Invalid Account&quot;);   \r\n }\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Function<\/strong><\/td>\n<td>\n<strong>Accounts.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@FunctionalInterface\r\npublic interface Accounts  \r\n{\r\n abstract String showAccountType(String accountType, String returnAccType);\r\n}\r\n<\/pre>\n<p><strong>AccountImpl.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  \/\/Implementation of Custom Function Method for Accounts Interface\r\n  Accounts squareRoot = (accountType, returnType) -&gt; {\r\n   if (accountType == &quot;Savings&quot;)\r\n    return &quot;Credit&quot;;\r\n   else\r\n    return &quot;Debit&quot;;\r\n  };\r\n\r\n  System.out.println(squareRoot.showAccountType(&quot;Savings&quot;, null));\r\n }\r\n}\r\n<\/pre>\n<p>The above code could be expanded as below using Anonymous Inner Class<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  Accounts squareRoot = new Accounts() {\r\n   @Override\r\n   public String showAccountType(String accountType, String returnAccType) {\r\n\r\n    if (accountType == &quot;Savings&quot;)\r\n     return &quot;Credit&quot;;\r\n    else\r\n     return &quot;Debit&quot;;\r\n   }\r\n  };\r\n\r\n  System.out.println(squareRoot.showAccountType(&quot;Savings&quot;, null));\r\n }\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>Urnary Operator<\/strong><\/td>\n<td>\n<strong>Accounts.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@FunctionalInterface\r\npublic interface Accounts{\r\n abstract String showAccountType(String accountType);\r\n}\r\n<\/pre>\n<p><strong>AccountImpl.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  \/\/Implementation of Custom Operator Method for Accounts Interface\r\n  Accounts squareRoot = (accountType) -&gt; {\r\n   return &quot;AccountType is &quot; + accountType;\r\n  };\r\n  squareRoot.showAccountType(&quot;Savings&quot;);\r\n }\r\n}\r\n<\/pre>\n<p>The above code could be expanded as below using Anonymous Inner Class<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class AccountImpl {\r\n public static void main(String&#x5B;] args) {\r\n  Accounts squareRoot = new Accounts() {\r\n   @Override\r\n   public String showAccountType(String accountType) {\r\n    return &quot;AccountType is &quot; + accountType;\r\n   }\r\n  };\r\n\r\n  System.out.println(squareRoot.showAccountType(&quot;Savings&quot;));\r\n }\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Supplier Accounts.java @FunctionalInterface public interface Accounts{ abstract String showAccountType(); } AccountImpl.java public class AccountImpl { public static void main(String&#x5B;] args) { \/\/Implementation of Custom Supplier Method for Accounts Interface Accounts squareRoot = () -&gt; &quot;Hi there&quot;; System.out.println(squareRoot.showAccountType()); } } The above code could be expanded as below using Anonymous Inner Class public class AccountImpl {&hellip; <a href=\"https:\/\/codethataint.com\/blog\/custom-functional-interface-definition-using-lamdas\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[250],"tags":[],"class_list":["post-3146","post","type-post","status-publish","format-standard","hentry","category-lambdas"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=3146"}],"version-history":[{"count":6,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3146\/revisions"}],"predecessor-version":[{"id":4279,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3146\/revisions\/4279"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}