def func(f: => Int) = f
这不到风度(内部类为例)
type EmptyFunct = => Int
或
type EmptyFunct = (=> Int)
斯卡拉版本2.9 两个问题:
- 为什么dosn't语法糖在第二种情况下工作?
- 如何定义不通过语法糖这个功能呢?
def func(f: => Int) = f
这不到风度(内部类为例)
type EmptyFunct = => Int
或
type EmptyFunct = (=> Int)
斯卡拉版本2.9 两个问题:
=> int是不完全不带参数的函数,它是一个int参数与由名字传递约定呼叫。 (当然,这是相当好的一点,因为它通过传递一个没有参数的函数来实现)。
的功能,但没有参数写入() => Int
。你可以做type EmptyFunct =() => Int
。
这是不是一个类型。在函数内部,f将被输入为Int。类型()=> Int的参数不会。
def func(f: => Int) = f *2
func (: => Int) Int
但
def func(f:() => Int) : Int = f*2
error: value * is not a member of() => Int
你能给EmptyFunct'的'使用显示为什么'()=> Unit'的例子不适合你的需要? – Nicolas