Using spark-shell v1.6.
Big differences when I load a class def and its companion object depending on how it's done.
- one line at a time - OK
- via
:paste
- PROBLEM
First things first... since the repl finds it ambiguous to load a companion object with the same name, I give it an altered name. No problem there. Setup lookes like this...
import scala.util.Try
class Foo5(val i: Int)
object Foo5Companion {
def apply(i: Int): Foo5 = new Foo5(i)
def apply(d: Double): Foo5 = new Foo5(d.toInt)
def applyTry(i: Int): Try[Foo5] = Try { apply(i) }
def applyTry(d: Double): Try[Foo5] = Try { apply(d) }
}
Now let's do something simple with this class.
val ls_i: List[Int] = List(1,2,3)
val ls_foo: List[Foo5] = ls_i.map(Foo5Companion.apply)
If I've loaded the class def and companion object with :paste
I get this error... to be clear, Foo5 has only been defined once in a new session. This is not an instance of the issue described here: "error: type mismatch" in Spark with same found and required datatypes
<console>:42: error: type mismatch;
found : List[Foo5]
required: List[Foo5]
val ls_foo: List[Foo5] = ls_i.map(Foo5Companion.apply)
BUT...
if i load the same defs in line-by-line (without using :paste
)... it works fine...
ls_foo: List[Foo5] = List($iwC$$iwC$Foo5@66f1a93a, $iwC$$iwC$Foo5@39d53a3, $iwC$$iwC$Foo5@4dddf42f)
My question is... what's the difference? Why is :paste
causing a problem and making the repl think Foo5
is ambiguous?