The Artima Developer Community
Sponsored Link

Java Buzz Forum
Static Method reference - BiFunction Overload methods | Method reference in Java 8

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Static Method reference - BiFunction Overload methods | Method reference in Java 8 Posted: Jun 12, 2017 12:59 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Static Method reference - BiFunction Overload methods | Method reference in Java 8
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

Click here to watch in Youtube :
https://www.youtube.com/watch?v=NVnYhSQoKHU&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Static Method reference - BiFunction Overload methods | Method reference in Java 8 
MethodReferenceDemo.java
import java.util.function.BiFunction;

/**
*
* We can also override static methods by referring methods. In the
* following example, we have defined and overloaded three add
* methods.
*
*/


class Arithmetic
{
public static int add(int a, int b)
{
return a + b;
}

public static float add(int a, float b)
{
return a + b;
}

public static float add(float a, float b)
{
return a + b;
}
}

public class MethodReferenceDemo
{
public static void main(String[] args)
{
BiFunction<Integer, Integer, Integer> adder1 = Arithmetic::add;
BiFunction<Integer, Float, Float> adder2 = Arithmetic::add;
BiFunction<Float, Float, Float> adder3 = Arithmetic::add;

int result1 = adder1.apply(10, 20);
System.out.println(result1);

float result2 = adder2.apply(10, 20.3f);
System.out.println(result2);

float result3 = adder3.apply(10.6f, 20.8f);
System.out.println(result3);
}
}
Output
30
30.3
31.4
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/LambdaDemo_method_ref_static_BiFunc_overload_app.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/LambdaDemo_method_ref_static_BiFunc_overload_app

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/525432e9afa25ee5052810cb2318f64453ffeffa/BasicJava/LambdaDemo_method_ref_static_BiFunc_overload_app/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Read: Static Method reference - BiFunction Overload methods | Method reference in Java 8

    Topic: Spring Integration Control Bus Example Previous Topic   Next Topic Topic: 32% off Horizon Zero Dawn For PlayStation 4 - Deal Alert

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use