LearnFrenzy
Sign in Take a free test

Lambda Expressions · Find the Error · Question 5

Error: mixing var with an explicit type in lambda parameters Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
import java.util.function.BiFunction;

public class Main {
    public static void main(String[] args) {
        BiFunction<Integer, Integer, Integer> add = (var a, Integer b) -> a + b;
        System.out.println(add.apply(2, 3));
    }
}
  • A var cannot hold Integers
  • B All lambda parameters must use the same style – all implicit, all var or all explicit types Correct
  • C BiFunction needs four types
  • D The body needs braces
Correct Answer: Option B

javac: "invalid lambda parameter declaration (cannot mix 'var' and explicitly-typed parameters)".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links