方法1
在需要隐式转换的地方,把需要的参数显示的写出。
略
方法2,查看编译代码
在terminal中 利用 scalac -Xprint:typer xxx.scala
方法打印添加了隐式值的代码示例。
对于复杂的工程来说,直接跑到terminal执行 scalac -Xprint:typer xxx.scala
会报很多库不存在的错误。
BasicTest.scala:5: error: object scalatest is not a member of package org
import org.scalatest.funsuite
^
BasicTest.scala:6: error: object apache is not a member of package org
import org.apache.log4j.Logger
^
BasicTest.scala:7: error: object json4s is not a member of package org
import org.json4s._
^
BasicTest.scala:8: error: object json4s is not a member of package org
import org.json4s.JsonDSL._
可在idea的设置中,找到如下配置,写入-Xprint:typer
再到要调试的文件页面,进行编译(快捷键Ctrl+Shift+F9)。然后编译结果就会打印,比如我的如下代码:文章来源:https://www.toymoban.com/news/detail-655311.html
test("json字段覆盖测试"){
var json = ("name" -> "joe") ~ ("age" -> 35)
LOGGER.info(compact(render(json)))
json ~ ("age" -> 38)
LOGGER.info(compact(render(json)))
var json2=parse("{\"name\":\"joe\",\"age\":35}")
json2 = json2 merge render("height",175)
}
编译输出:文章来源地址https://www.toymoban.com/news/detail-655311.html
BasicTest.this.test("json�ֶθ���")({
var json: org.json4s.JsonAST.JObject = org.json4s.JsonDSL.pair2Assoc[String](scala.Predef.ArrowAssoc[String]("name").->[String]("joe"))({
((x: String) => org.json4s.JsonDSL.string2jvalue(x))
}).~[Int](scala.Predef.ArrowAssoc[String]("age").->[Int](35))({
((x: String) => org.json4s.JsonDSL.string2jvalue(x))
}, {
((x: Int) => org.json4s.JsonDSL.int2jvalue(x))
});
BasicTest.this.LOGGER.info(org.json4s.jackson.JsonMethods.compact({
<artifact> val x$1: org.json4s.JsonAST.JObject = json;
<artifact> val x$2: org.json4s.Formats = org.json4s.jackson.JsonMethods.render$default$2(x$1);
org.json4s.jackson.JsonMethods.render(x$1)(x$2)
}));
org.json4s.JsonDSL.jobject2assoc(json).~(org.json4s.JsonDSL.pair2jvalue[Int](scala.Predef.ArrowAssoc[String]("age").->[Int](38))({
((x: Int) => org.json4s.JsonDSL.int2jvalue(x))
}));
BasicTest.this.LOGGER.info(org.json4s.jackson.JsonMethods.compact({
<artifact> val x$3: org.json4s.JsonAST.JObject = json;
<artifact> val x$4: org.json4s.Formats = org.json4s.jackson.JsonMethods.render$default$2(x$3);
org.json4s.jackson.JsonMethods.render(x$3)(x$4)
}));
var json2: org.json4s.JValue = org.json4s.jackson.JsonMethods.parse(org.json4s.`package`.string2JsonInput("{\"name\":\"joe\",\"age\":35}"), org.json4s.jackson.JsonMethods.parse$default$2, org.json4s.jackson.JsonMethods.parse$default$3);
json2 = JsonAST.this.JValue.j2m[org.json4s.JValue](json2).merge[org.json4s.JValue, org.json4s.JsonAST.JValue]({
<artifact> val x$5: org.json4s.JsonAST.JObject = org.json4s.JsonDSL.pair2jvalue[Int](scala.Tuple2.apply[String, Int]("height", 175))({
((x: Int) => org.json4s.JsonDSL.int2jvalue(x))
});
<artifact> val x$6: org.json4s.Formats = org.json4s.jackson.JsonMethods.render$default$2(x$5);
org.json4s.jackson.JsonMethods.render(x$5)(x$6)
})(JsonAST.this.JValue.jjj[org.json4s.JValue, org.json4s.JValue])
})((Position.apply("BasicTest.scala", "Please set the environment variable SCALACTIC_FILL_FILE_PATHNAMES to yes at compile time to enable this feature.", 27): org.scalactic.source.Position))
}
到了这里,关于Scala 如何调试隐式转换--隐式转换代码的显示展示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!