2016-11-10 4 views
2
import com.alibaba.fastjson.JSON 

object test { 
    def main(args: Array[String]) = { 
    val map = new util.HashMap[CharSequence, CharSequence]() 
    map.put("123", "22333") 
    map.put("test", null) 
    val ret = JSON.toJSONString(map) 
    println(ret) 
    } 
} 

toJSONString functiones :모호한 참조 할 때 자바 라이브러리의 호출 방법

오류 : 어떤 이유

Error:ambiguous reference to overloaded definition,both method toJSONString in object JSON of 
type (x$1: Any, x$2: com.alibaba.fastjson.serializer.SerializerFeature*)String 
and method toJSONString in object JSON of 
type (x$1: Any)String 
match argument types (java.util.HashMap[CharSequence,CharSequence]) 
val ret = JSON.toJSONString(map) 
+0

https://issues.scala-lang.org/browse/SI-8344 여기서'f (a, b, c)'는'f (Tuple3 (a, b, c))'로 간주 할 수 있습니다. –

답변

0

는 스칼라 오버로드 로직 자바 로직과 일치하지 않습니다 . 다음과 같이 호출해야합니다.

JSON.toJSONString(map, SerializerFeature.PrettyFormat) 

좋은 하루 되세요!