<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/">

<channel>
	<title>consumer Archives - Manish Sanger</title>
	<atom:link href="https://www.manishsanger.com/tag/consumer/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.manishsanger.com/tag/consumer/</link>
	<description>Java, J2EE, Spring Framework, application security,big data,database,design patterns,hibernate,j2ee,java,jdbc,micro-services,mongodb,multithreading,nosql</description>
	<lastBuildDate>Thu, 04 Jan 2018 12:11:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>Functional Interface &#8211; Java 8</title>
		<link>https://www.manishsanger.com/functional-interface/</link>
					<comments>https://www.manishsanger.com/functional-interface/#comments</comments>
		
		<dc:creator><![CDATA[manishsanger]]></dc:creator>
		<pubDate>Wed, 03 Jan 2018 10:41:05 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[java 8]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[functional interface]]></category>
		<category><![CDATA[predicate]]></category>
		<category><![CDATA[consumer]]></category>
		<guid isPermaLink="false">https://www.manishsanger.com/?p=282</guid>

					<description><![CDATA[<p>Java has always been an Object Oriented programming language, it means we can&#8217;t have a function without its class. Other programming languages like C++, PHP, Python, JavaScript and many more, where we write functions and use anywhere, all these languages support functional programming along with Object Oriented programming. Java introduced Functional interface &#38; Lambda Expressions [&#8230;]</p>
<p>The post <a href="https://www.manishsanger.com/functional-interface/">Functional Interface &#8211; Java 8</a> appeared first on <a href="https://www.manishsanger.com">Manish Sanger</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Java has always been an <strong>Object Oriented</strong> programming language, it means we can&#8217;t have a function without its class. Other programming languages like C++, PHP, Python, JavaScript and many more, where we write functions and use anywhere, all these languages support functional programming along with Object Oriented programming.</p>
<p>Java introduced Functional interface &amp; Lambda Expressions in Java 8, to leverage functional programming to reduce verbosity.</p>
<p><strong>What is functional Interface?</strong></p>
<p>A <em>Functional Interface</em> is an interface which specifies exactly one abstract method. Its implementation may be treated as Lambda Expression.</p>
<p>Note: An interface is still a functional interface if it has many default methods, as long as it specifies only one abstract method.</p>
<p>Since default methods have an implementation, they are not abstract. If an interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface&#8217;s abstract method count since any implementation of the interface will have an implementation from java.lang.Object or elsewhere</p>
<p>While the main use of Functional interfaces is for lambda expressions, method references, and constructor references, they can still be used, like any interface, with anonymous classes, implemented by classes, or created by factory methods.</p>
<p>Java 8 provides some inbuilt functional interfaces like <em>Comparable, Runnable, Callable</em> etc.</p>
<p>If you want to define any functional interface of your own, you can use annotation @FunctionalInterface for compiler level errors. It will allow to specify only one abstract method.</p>
<p>Example:</p>
<pre><code class="java">@FunctionalInterface<br />
public interface SomeInterface {<br />
public String someMethod(String param);<br />
}<br />
</code></pre>
<p>A functional interface is valid even if the @FunctionalInterface annotation would be omitted. It is only for informing the compiler to enforce single abstract method inside interface.</p>
<pre><code class="java">Public interface SomeInterface {<br />
String someMethod(String param);<br />
}</p>
<p>//With default method<br />
@FunctionalInterface<br />
Public interface SomeInterface {<br />
public String someMethod(String param);<br />
default void someDefaultMethod(){<br />
//method Implementation<br />
}</p>
<p>}</p>
<p>// When overriding methods from the java.lang.Object</p>
<p>@FunctionalInterface<br />
Public interface SomeInterface {<br />
public String someMethod(String param);<br />
@Override<br />
public String toString();  //Overridden from Object class</p>
<p>@Override<br />
public boolean equals(Object obj); //Overridden from Object class</p>
<p>}<br />
</code></pre>
<p>The signature of abstract method in functional interface is called <strong>Functional descriptor</strong> because it defines the signature of the lambda expression.</p>
<p>Java 8 has introduced several functional interfaces in java.util.function package which can be used to describe the signature of various lambda expressions.</p>
<p>Here is the complete list of functional interfaces available in java.util.functional:</p>
<p>1. <a href="https://www.manishsanger.com/predicate/">Predicate</a><br />
2. Consumer<br />
3. Function&lt;T, R&gt;<br />
4. Supplier<br />
5. UnaryOperator<br />
6. BinaryOperator<br />
7. BiPredicate&lt;L, R&gt;<br />
8. BiConsumer&lt;T, U&gt;<br />
9. BiFunction&lt;T, U, R&gt;</p>
<p>The post <a href="https://www.manishsanger.com/functional-interface/">Functional Interface &#8211; Java 8</a> appeared first on <a href="https://www.manishsanger.com">Manish Sanger</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.manishsanger.com/functional-interface/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
