如何在scala中实现接口Serializable? [英] How to implement interface Serializable in scala?

查看:102
本文介绍了如何在scala中实现接口Serializable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像这样的 Scala 类:

I have scala class like:

@Entity("users")
class User(@Required val cid: String, val isAdmin: Boolean = false, @Required val dateJoined: Date = new Date() ) {
  @Id var id: ObjectId = _



    @Reference
  val foos = new ArrayList[Foo]

    }

如果它是一个 Java 类,我会简单地放置实现 java.io.Serializable 但这在 Scala 中不起作用.上面声明的 foos 是私有的还是公共的?

If it was a Java class I would simply put implements java.io.Serializable but this does not work in scala. Also is foos as declared above is private or public?

推荐答案

scala 2.9.x 也有一个名为 Serializable 的接口,你可以扩展或混合它.在 2.9.x 之前,@serializable 是唯一的选择.

scala 2.9.x also have an interface named Serializable, you may extends or mixin this. before 2.9.x the @serializable is the only choice.

这篇关于如何在scala中实现接口Serializable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆