This page is no longer maintained — Please continue to the home page at www.scala-lang.org

deprecate @serializable?

3 replies
rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Hi,
  @serializable class X
is identical to
  class X extends Serializable
except for a small difference that most don't know and sometimes bites people (http://lampsvn.epfl.ch/trac/scala/ticket/3924)
The reason is that the compiler converts the annotation only during type-checking, so depending on the order in which things type check,there might be an error message ("required: Serializable") or not.
The correct behavior would be to do the transformation earlier, but this is kind of a hack as some of you know (@BeanProperty), and we reallywant to avoid more annotations that influence typing.

If we remember correctly the annotation was added to have a uniform approach for JVM and .NET. But there would be another way to do that,something like
in Scala (JVM version)  package scala  trait Serializable extends java.lang.Serializable
in Scala.NET  package scala  trait Serializable

So we propose to deprecate the @serializable annotation.
Comments?
Lukas
Sam Stainsby
Joined: 2009-01-14,
User offline. Last seen 42 years 45 weeks ago.
Re: deprecate @serializable?

Arrrg, I was assuming they were identical. Sounds reasonable to deprecate
the annotation unless there is some added value in it hitherto
unmentioned.

( ... now to clean up some code)

Erik Engbrecht
Joined: 2008-12-19,
User offline. Last seen 3 years 18 weeks ago.
Re: deprecate @serializable?
I thought the purpose of @serializable was to enable proper generation of the serialVersionUid static final member of the class, because Scala doesn't have static fields.

On Tue, Oct 19, 2010 at 9:28 AM, Lukas Rytz <lukas [dot] rytz [at] epfl [dot] ch> wrote:
Hi,
  @serializable class X
is identical to
  class X extends Serializable
except for a small difference that most don't know and sometimes bites people (http://lampsvn.epfl.ch/trac/scala/ticket/3924)
The reason is that the compiler converts the annotation only during type-checking, so depending on the order in which things type check,there might be an error message ("required: Serializable") or not.
The correct behavior would be to do the transformation earlier, but this is kind of a hack as some of you know (@BeanProperty), and we reallywant to avoid more annotations that influence typing.

If we remember correctly the annotation was added to have a uniform approach for JVM and .NET. But there would be another way to do that,something like
in Scala (JVM version)  package scala  trait Serializable extends java.lang.Serializable
in Scala.NET  package scala  trait Serializable

So we propose to deprecate the @serializable annotation.
Comments?
Lukas



--
http://erikengbrecht.blogspot.com/
Alex Hvostov
Joined: 2010-06-15,
User offline. Last seen 42 years 45 weeks ago.
Re: deprecate @serializable?

On Tue, 2010-10-19 at 20:30 -0400, Erik Engbrecht wrote:
> I thought the purpose of @serializable was to enable proper generation
> of the serialVersionUid static final member of the class, because
> Scala doesn't have static fields.

No, that's what the @SerialVersionUID annotation (also in the scala
package) is for. You can even do this:

@SerialVersionUID(42)
class Foo extends java.io.Serializable

This does what it should, namely include a serialVersionUID field on
classOf[Foo].

If we're going to deprecate @serializable and introduce a trait
scala.Serializable, note that we still need @SerialVersionUID (instead
of an abstract val on scala.Serializable) because the serialVersionUID
field is *not* supposed to be inherited.

Alex

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland