mercredi 29 mars 2017

The difference between running a scala script directly vs through a scala shell

I ran into the "No TypeTag available for" error when running a simple script:

import scala.reflect.runtime.{universe => ru} 
case class Person(name: String)
val classPerson = ru.typeOf[Person].typeSymbol.asClass

The script is an example from Scala Reflection Doc. According to this post, the error is caused by the fact that the case class is not defined at the top level. I know scala automatically compiles a scala script into a class before running it, thus making the case class a internally defined class, but the same script would work if it is run in a scala shell. So what is the difference between running a scala script and running the same script through the scala shell?





Aucun commentaire:

Enregistrer un commentaire