Strange syntax for instantiating an inner class

前端 未结 6 1827
慢半拍i
慢半拍i 2020-12-05 09:12

I didn\'t imagine that I would encounter radically new syntax in Java anymore at this stage, but lo and behold, I just encountered something:

The exact context a

6条回答
  •  無奈伤痛
    2020-12-05 09:59

    Your code would compile, had you typed

    buttonClick(new Button().ClickEvent(button));
    

    instead of

    buttonClick(new Button.ClickEvent(button));

    as a constructor is a method and when you call a method in Java you must pass the list of arguments, even when it is empty.

提交回复
热议问题