Skip to content

Instantly share code, notes, and snippets.

@kmizu
Forked from maiha/ArrayBuffer.scala
Created November 18, 2010 03:38
Show Gist options
  • Save kmizu/704589 to your computer and use it in GitHub Desktop.
Save kmizu/704589 to your computer and use it in GitHub Desktop.
class Foo {
import scala.collection.mutable.ArrayBuffer
val elements = List(1,2,3)
//ClassManifest is needed
def map[T:ClassManifest](block: Int => T) = {
val vals = ArrayBuffer[T]()
elements foreach{ i => vals += block(i) }
vals.toArray
}
}
// passed (scala-2.8.1)
class Foo {
import scala.collection.mutable.ListBuffer
val elements = List(1,2,3)
def map[T](block: Int => T) = {
val vals = ListBuffer[T]()
elements foreach{ i => vals += block(i) }
vals.toList
}
}
// passed (scala-2.8.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment