我想学习 Java 的“新”语法和 API 中的可能性。更新我的意思是 10+(比方说 10-13)。它主要围绕 lambdas 的声明和存储与映射中的值相同的签名的不同实现。最近我主要和 Gosu 一起工作,我可以用这个片段:
var longInput = 10000000L
new LinkedHashMap<String, block(long) : long>( {
"byte" -> (\x -> x as byte as long),
"short" -> (\x -> x as short as long),
"int" -> (\x -> x as int as long),
"long" -> (\x -> x as long as long)
}).eachKeyAndValue(\key, value ->
print("${longInput} ${value(longInput) == longInput ? "can" : "cannot"} be converted to ${key}")
)
Run Code Online (Sandbox Code Playgroud)
我可以在 Java 10 中类似地做到这一点:
import java.util.*;
public …
Run Code Online (Sandbox Code Playgroud)