Why does an empty lambda and constructor with an explicit return cause a compiler error (Java Bug?)

后端 未结 1 1736
别那么骄傲
别那么骄傲 2020-12-11 02:09

I have a reproducible test case:

public class TestCase {

    private final java.util.function.Consumer emptyCallback = result -> {};

    p         


        
      
      
      
1条回答
  •  醉梦人生
    2020-12-11 02:41

    You can find an official bug report here. The issue is fixed in Java 9.


    You can return inside a constructor

    A return statement returns control to the invoker of a method (§8.4, §15.12) or constructor (§8.8, §15.9).

    0 讨论(0)
提交回复
热议问题