scala - 如何知道分配了哪个功能?
问题描述
如果我有这样的事情:
def fn1(a:Integer)="1"
def fn2(a:Integer)="2"
val f=fn2 _
if( f== fn1 _) "1" else if(f==fn2 _) "2" else "other"
始终返回“其他”。如何在代码中知道哪个函数分配给了 f?
解决方案
这也有效:
def fn1(a:Integer)="1"
def fn2(a:Integer)="2"
val f1=fn1 _
val f2=fn2 _
val f=f2
f match {
case `f1` => "1"
case `f2` => "2"
case _ => "other"
}
推荐阅读
- c++ - libcurl:curl_easy_perform 块,除非设置了 CURLOPT_READFUNCTION
- google-compute-engine - GKE网络绑定kubernetes节点?
- c# - 无法在另一台计算机上打开 c# winform 项目
- c++ - C++ WinApi OpenCV 网络摄像头 - 如何从 Mat 帧中获取和保存数组中的所有像素值以及如何稍后显示
- python - 在生成器函数上使用 next()
- php - 尝试从数据库中选择 WooCommerce 值时出现 mysqli_fetch_assoc 错误
- linux - 如何减少 Pentaho Server 使用的 RAM?
- python - 根据 ID 将 numpy 行转换为列
- java - MissingResourceException,除了资源在那里
- swift - iOS 11 Swift 4 将 ChildViewController 添加到 UISCrollView 不会占用全部高度