【问题标题】:Scala - Is that a closure?Scala - 这是一个闭包吗?
【发布时间】:2014-10-21 14:28:10
【问题描述】:

我不确定我刚刚写的代码是否可以称为闭包,这里是:

withExistingDataSource(dataSourceId, dataSource => checkDataSourceTypeAndFetchDataFromAgent(dataSource, theQuery))

参见下面的上一个方法签名:

private def withExistingDataSource(dataSourceId: Long, success: DataSource => Result): Result

我可以说:

dataSource => checkDataSourceTypeAndFetchDataFromAgent(dataSource, theQuery) 

是闭包吗?

【问题讨论】:

    标签: scala closures


    【解决方案1】:

    是的。

    函数的结果取决于函数外部定义的theQuery变量。

    【讨论】:

    • 如果我去掉 theQuery 参数会怎样?
    • 那么你就有了一个函数
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 2011-05-26
    • 2013-07-04
    • 1970-01-01
    相关资源
    最近更新 更多