Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created April 30, 2012 02:49
Show Gist options
  • Save xuwei-k/2555107 to your computer and use it in GitHub Desktop.
Save xuwei-k/2555107 to your computer and use it in GitHub Desktop.
scala android Parcelable
import android.os.{Parcel,Parcelable}
class A(in:Parcel) extends android.os.Parcelable{
override def describeContents():Int = 0
override def writeToParcel(out:Parcel,flag:Int){
}
val CREATOR:Parcelable.Creator[A] = new Parcelable.Creator[A]() {
def createFromParcel(in:Parcel):A = {
new A(in)
}
def newArray(size:Int):Array[A] = {
new Array[A](size)
}
}
}
scalaVersion := "2.9.2"
libraryDependencies += "com.google.android" % "android" % "4.0.1.2"
public class A extends java.lang.Object implements android.os.Parcelable,scala.ScalaObject{
public static final android.os.Parcelable$Creator CREATOR;
public static {};
public int describeContents();
public void writeToParcel(android.os.Parcel, int);
public android.os.Parcelable$Creator CREATOR();
public A(android.os.Parcel);
}
@brantYan
Copy link

Hi xuwei-k
can you show me an example how to use this?

@magicgoose
Copy link

Hello. Can you explain why/how this code generates STATIC field? Previously I've heard that this is not possible in scala without writing compiler plugins. So this is very interesting.

@mkneissl
Copy link

@magicgoose It's scala compiler magic. There is an explicit special case for Parcelable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment