在这个简单的例子中,sbt run失败了

时间:2016-11-04 08:42:50

标签: sbt

这是使用sbt run时显示一个非常奇怪的事情的最小例子。试图使示例更小,然后问题不再出现。我错过了什么或者这是一个错误还是sbt

build.sbt

name := "testsbt"

version := "1.0"

scalaVersion := "2.11.8"

项目/ build.properties

sbt.version = 0.13.13

的src /主/阶/应用/ Test.scala

package application

import java.io._

case class Page(items: List[Item])
case class Item(text: String)

object Test extends App {
    val page = Page(List(Item("item1")))

    val filename = "./page.obj"

    val oos = new ObjectOutputStream(new FileOutputStream(filename))
    try oos.writeObject(page)
    finally oos.close()

    println("read: " + new ObjectInputStream(new FileInputStream(filename)).readObject())
}

使用sbt run执行此操作失败:

$ sbt run 
[error] (run-main-0) java.lang.ClassCastException: cannot assign instance of scala.collection.immutable.List$SerializationProxy to field application.Page.items of type scala.collection.immutable.List in instance of application.Page

然而,执行sbt包并从中运行:

$ sbt package
$ scala -cp target/scala-2.11/testsbt_2.11-1.0.jar application.Test
read: Page(List(Item(item1)))

0 个答案:

没有答案