Discussion
Which line contains the error?
public class Sample60
{
interface Op { int apply(int v); }
public static void main(String[] args)
{
Op twice = v ->
{
assert v >= 0 : v;
return v * 2;
};
System.out.println(twice.apply(-3));
}
}
Answer: D
Assertions are perfectly legal inside a lambda body, and this one states a reasonable precondition. The error is the call, which passes -3 and so breaks the stated invariant. With -ea it reports an AssertionError carrying -3; without it the method quietly returns -6.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development