Skip to content

Instantly share code, notes, and snippets.

@maiha
Created November 17, 2010 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save maiha/703663 to your computer and use it in GitHub Desktop.
Save maiha/703663 to your computer and use it in GitHub Desktop.
ArrayBuffer_vs_ListBuffer
class Foo {
import scala.collection.mutable.ArrayBuffer
val elements = List(1,2,3)
def map[T](block: Int => T) = {
val vals = ArrayBuffer[T]()
elements foreach{ i => vals += block(i) }
vals.toArray
}
}
// faild (scala-2.8.1)
error: could not find implicit value for evidence parameter of type ClassManifest[T]
vals.toArray
^
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