Answers for "functional interface in java 8 example"

1

creating the functional interface in java

package com.concretepage;

@FunctionalInterface
public interface Calculator {
   long calculate(long num1, long num2);
}
Posted by: Guest on February-17-2020
0

functional interface in java 8 example

@FunctionalInterface
interface Square
{
    int calculate(int x);
}
  
class Test
{
    public static void main(String args[])
    {
        int a = 5;
  
        // lambda expression to define the calculate method
        Square s = (int x)->x*x;
  
        // parameter passed and return type must be
        // same as defined in the prototype
        int ans = s.calculate(a);
        System.out.println(ans);
    }
}
Posted by: Guest on June-28-2021

Code answers related to "functional interface in java 8 example"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language