Can a function return a function?



Can a function return a function?..

Answer / Sanjeev Yadav

Yes, in Java 8 and later versions, you can use functional interfaces such as Runnable, Callable, or Supplier to define functions that return other functions. Here's an example using the Functional Interface Function<T,R> :n`nFunction<Integer, Function<Integer, Integer>> squares = n -> i -> n * i * i;nFunction<Integer, Integer> squareOfFive = squares.apply(5);nSystem.out.println(squareOfFive.apply(3)); // outputs 150n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

How do you check if two strings are equal in java?

1 Answers  


why should we get the following error ? Exception in main method NoClassDefFoundError:classname could anyone give the detail clarification on how java compiler can look for .class file?

2 Answers  


hoe can u call a constructor of a private classs to other inherited claa??

1 Answers  


Different types of Layouts?

11 Answers  


Can we use switch statement with strings?

1 Answers  


What is left shift and right shift?

1 Answers  


How arrays are stored in memory in java?

1 Answers  


Write a program to find maximum and minimum number in array?

1 Answers  


What is garbage collector?

1 Answers  


what is ABSTRACTION and what are using in real time project?

1 Answers   iGate,


int a=10,b=20,c=30 a= b+c;b=a+c;c=a+b; System.out.println("The value is"+a+b+c;

17 Answers   Honeywell,


Explain the init method?

1 Answers  


Categories