forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The instances may be captured by closures, which should be serializable. Fixes scala/bug#10522
- Loading branch information
Showing
4 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
gi init x | ||
1 | ||
1 | ||
gi init x | ||
1 | ||
1 | ||
gs init x | ||
hi | ||
hi | ||
gs init x | ||
hi | ||
hi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
object Test { | ||
def serializeDeserialize[T <: AnyRef](obj: T): T = { | ||
import java.io._ | ||
val buffer = new ByteArrayOutputStream | ||
val out = new ObjectOutputStream(buffer) | ||
out.writeObject(obj) | ||
val in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray)) | ||
in.readObject.asInstanceOf[T] | ||
} | ||
|
||
def gi: () => Int = { | ||
lazy val x = { println("gi init x"); 1 } | ||
serializeDeserialize(() => x) | ||
} | ||
|
||
def gs: () => String = { | ||
lazy val x = { println("gs init x"); "hi" } | ||
serializeDeserialize(() => x) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
val fi1 = gi | ||
println(fi1()) | ||
println(fi1()) | ||
|
||
val fi2 = gi | ||
println(fi2()) | ||
println(fi2()) | ||
|
||
val fs1 = gs | ||
println(fs1()) | ||
println(fs1()) | ||
|
||
val fs2 = gs | ||
println(fs2()) | ||
println(fs2()) | ||
} | ||
} |