임의 반환하고,이 Some
을 제거하는 쉬운 방법이 Some[String]
스칼라지도 # get 및 및 스칼라 <code>Map#get</code> 기능을 사용하여 일부()
로 반환 모든 정확한 쿼리?
예 :
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
마지막으로,이 같은
Option
유형에 일치하는 패턴을 사용하는 것도 인기 -in-scala –'Option'에 대한 멋진 점은'None' case를 처리해야한다는 것입니다. –