No-argument constructor in Spark Shell / Scala REPL

我是研究僧i 提交于 2019-12-11 03:35:33

问题


In spark-shell (which uses scala-repl), it seems impossible to make a (case) class which has the default constructor (i.e. no-argument constructor):

scala> case class Hello(i: Int) {
      |   def this() = this(0)
      | }
defined class Hello

scala> classOf[Hello].getName
res1: String = Hello

scala> classOf[Hello].getConstructors()
res2: Array[java.lang.reflect.Constructor[_]] = Array(public Hello($iw), public Hello($iw,int))

This makes Jackson fail to deserialize something into this class, because there isn't a simple way to construct an instance of that class using reflection.

Is it possible to make a case class have a default constructor in spark shell?

来源:https://stackoverflow.com/questions/30592985/no-argument-constructor-in-spark-shell-scala-repl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!