What's the difference between => , ()=>, and Unit=>

后端 未结 4 1788
深忆病人
深忆病人 2020-11-22 16:40

I\'m trying to represent a function that takes no arguments and returns no value (I\'m simulating the setTimeout function in JavaScript, if you must know.)

c         


        
4条回答
  •  耶瑟儿~
    2020-11-22 17:46

    I do it this way (just don't want to break apply):

    case class Thing[A](..., lazy: () => A) {}
    object Thing {
      def of[A](..., a: => A): Thing[A] = Thing(..., () => a)
    }
    

    and call it

    Thing.of(..., your_value)
    

提交回复
热议问题