Created
September 2, 2011 15:08
-
-
Save bmc/1188867 to your computer and use it in GitHub Desktop.
Scala compiler oddity #1
This file contains hidden or 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
// So, given this declaration: | |
import java.io.File | |
val scalaDirs = new File("target").listFiles.filter(_.getName.startsWith("scala")) | |
// Why does this work: | |
scalaDirs.take(1).map(new File(_, "classes")).toList(0) | |
// but this fails to compile? | |
scalaDirs.take(1).map(new File(_, "classes")).toArray(0) | |
// <console>:15: error: type mismatch; | |
// found : Int(0) | |
// required: scala.reflect.ClassManifest[?] | |
// res8.take(1).map(new File(_, "classes")).toArray(0) | |
// This also fails to compile, though the error is slightly different: | |
scalaDirs.take(1).map(new File(_, "classes"))(0) | |
// <console>:15: error: type mismatch; | |
// found : Int(0) | |
// required: scala.collection.generic.CanBuildFrom[Array[java.io.File],java.io.File,?] | |
// res8.take(1).map(new File(_, "classes"))(0) | |
// ... even though | |
scalaDirs.take(1).map(new File(_, "classes")) | |
// is of type Array[File] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you'll find that Josh and I agree with you.