Im的使用Scala的Map#get
函数的返回,并为它返回的Some[String]
斯卡拉地图#get和一些()
有一个简单的方法来去除Some
每一个准确的查询?
实施例:
def searchDefs{
print("What Word would you like defined? ")
val selection = readLine
println(selection + ":\n\t" + definitionMap.get(selection))
}
当我用这个方法,并使用以下输入:
What Word would you like defined? Ontology
返回的值是:
Ontology:
Some(A set of representational primitives with which to model a domain of knowledge or discourse.)
我想删除一些()周围。
任何提示?
参见:http://stackoverflow.com/questions/9364250/working-with-some-and-option -in-scala – 2012-02-22 07:48:21
关于Option的奇妙之处在于它迫使你处理'None'的情况。 – 2012-02-22 14:55:04