Skip to content

Instantly share code, notes, and snippets.

@walf443
Last active September 11, 2017 11:27
Show Gist options
  • Save walf443/fee95ac45f7d5b38d380609430dd177b to your computer and use it in GitHub Desktop.
Save walf443/fee95ac45f7d5b38d380609430dd177b to your computer and use it in GitHub Desktop.
interfaceをSerializableにして問題ないか検証してみた
import java.io.*
interface OnClickListener: Serializable {
fun onClick()
}
fun main(args: Array<String>) {
val l: OnClickListener = object: OnClickListener {
override fun onClick() {
println("\nhello kt")
}
}
val fos = FileOutputStream("tmp.txt")
val oos = ObjectOutputStream(fos)
oos.writeObject(l)
oos.close()
fos.close()
val oos2 = ObjectOutputStream(System.out)
oos2.writeObject(l)
val fis = FileInputStream("tmp.txt")
val ois = ObjectInputStream(fis)
val listener: OnClickListener = ois.readObject() as OnClickListener
listener.onClick()
ois.close()
fis.close()
}
@walf443
Copy link
Author

walf443 commented Sep 11, 2017

出力

����sr��MainKt$main$l$1��jP��w���xp
hello kt

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