Why can't I assign lambda to Object?

后端 未结 2 1715
广开言路
广开言路 2020-11-29 11:07

I was trying to assign a lambda to Object type:

Object f = ()->{};

And it gives me error saying:

 The target type of thi         


        
2条回答
  •  无人及你
    2020-11-29 12:00

    It's not possible. As per the error message Object is not a functional interface, that is an interface with a single public method so you need to use a reference type that is, e.g.

    Runnable r = () -> {}; 
    

提交回复
热议问题