Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scala> trait A
- defined trait A
- scala> class B extends A
- defined class B
- scala> class C extends A
- defined class C
- scala> Some(0).fold(new B){_=>new C}
- <console>:11: error: type mismatch;
- found : C
- required: B
- Some(0).fold(new B){_=>new C}
- scala> def meth[A](a1: A, a2: A) = (a1, a2)
- meth: [A](a1: A, a2: A)(A, A)
- scala> meth(1, "")
- res7: (Any, Any) = (1,"")
- scala> def meth[A](a1: A)(a2: A) = (a1, a2)
- meth: [A](a1: A)(a2: A)(A, A)
- scala> meth(1)("")
- <console>:10: error: type mismatch;
- found : String("")
- required: Int
- meth(1)("")
- ^
- scala> List(1).foldLeft(Nil)((xs,x) => x::xs)
- <console>:8: error: type mismatch;
- found : List[Int]
- required: scala.collection.immutable.Nil.type
- List(1).foldLeft(Nil)((xs,x) => x::xs)
- ^
- scala> List(1).foldLeft(Nil)((xs,x) => x::xs)
- <console>:8: error: type mismatch;
- found : List[Int]
- required: scala.collection.immutable.Nil.type
- List(1).foldLeft(Nil)((xs,x) => x::xs)
- ^
- scala> List(1).foldLeft(Nil : List[Int])((xs,x) => x::xs)
- res1: List[Int] = List(1)
- Some(0).fold(new B : A){_=>new C}
- Some(0).fold(new B: A){_=>new C}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement