|
Scala example source code file (t2214.scala)
The Scala t2214.scala source codeobject InvestmentType extends Enumeration { val Debt = Value("DEBT") val Future = Value("FUTURE") val Equity = Value("EQUITY") } object Test { def main(args: Array[String]) = { val buf = new java.io.ByteArrayOutputStream val oos = new java.io.ObjectOutputStream(buf) InvestmentType.values.foreach {i => oos.writeObject(i)} oos.flush oos.close val ois = new java.io.ObjectInputStream( new java.io.ByteArrayInputStream(buf.toByteArray)) var obj: Object = null foreach(ois) { obj => obj match { case InvestmentType.Debt => println("got " + obj) case InvestmentType.Equity => println("got " + obj) case InvestmentType.Future => println("got " + obj) case _ => println("unknown: " + obj + " of: " + obj.getClass) } } } def foreach(os: java.io.ObjectInputStream)(f: Object => Unit) { try { val obj = os.readObject if (obj != null) { f(obj) foreach(os)(f) } } catch { case e: java.io.EOFException => //IGNORE } } } Other Scala examples (source code examples)Here is a short list of links related to this Scala t2214.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.