The code example has a run-time type error on the line I’ve indicated.
Do I understand correctly that type erasure allows code to compile which is not type-safe?
// this is a type error pairList(li) returns List[((B,B),(B,B))] not List[(B,B)]
The run-time error exhibits when I run it in IntelliJ.
mList=List((1,2), (3,4), (5,6), (7,8), (9,10), (11,12), (13,14), (15,16), (17,18), (19,20), (21,22), (23,24), (25,26), (27,28), (29,30), (31,32), (33,34), (35,36), (37,38), (39,40), (41,42), (43,44), (45,46), (47,48), (49,50), (51,52), (53,54), (55,56), (57,58), (59,60), (61,62), (63,64), (65,66), (67,68), (69,70), (71,72), (73,74), (75,76), (77,78), (79,80), (81,82), (83,84), (85,86), (87,88), (89,90), (91,92), (93,94), (95,96), (97,98), (99,100)) leftover=None
li=List((1,2), (3,4), (5,6), (7,8), (9,10), (11,12), (13,14), (15,16), (17,18), (19,20), (21,22), (23,24), (25,26), (27,28), (29,30), (31,32), (33,34), (35,36), (37,38), (39,40), (41,42), (43,44), (45,46), (47,48), (49,50), (51,52), (53,54), (55,56), (57,58), (59,60), (61,62), (63,64), (65,66), (67,68), (69,70), (71,72), (73,74), (75,76), (77,78), (79,80), (81,82), (83,84), (85,86), (87,88), (89,90), (91,92), (93,94), (95,96), (97,98), (99,100)) maybeB=None
li=List(((3,4),(1,2)), ((7,8),(5,6)), ((11,12),(9,10)), ((15,16),(13,14)), ((19,20),(17,18)), ((23,24),(21,22)), ((27,28),(25,26)), ((31,32),(29,30)), ((35,36),(33,34)), ((39,40),(37,38)), ((43,44),(41,42)), ((47,48),(45,46)), ((51,52),(49,50)), ((55,56),(53,54)), ((59,60),(57,58)), ((63,64),(61,62)), ((67,68),(65,66)), ((71,72),(69,70)), ((75,76),(73,74)), ((79,80),(77,78)), ((83,84),(81,82)), ((87,88),(85,86)), ((91,92),(89,90)), ((95,96),(93,94)), ((99,100),(97,98))) maybeB=None
Exception in thread "main" java.lang.ClassCastException: scala.Tuple2 cannot be cast to java.lang.Integer
at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:103)
at scala.runtime.java8.JFunction2$mcIII$sp.apply(JFunction2$mcIII$sp.java:23)
at treereduce.TreeParallelReduce$.$anonfun$pairMapReduce$1(TreeParallelReduce.scala:95)
at scala.collection.immutable.List.map(List.scala:286)
at treereduce.TreeParallelReduce$.recur$1(TreeParallelReduce.scala:95)
at treereduce.TreeParallelReduce$.pairMapReduce(TreeParallelReduce.scala:113)
at treereduce.TreeParallelReduce$.main(TreeParallelReduce.scala:123)
at treereduce.TreeParallelReduce.main(TreeParallelReduce.scala)
Process finished with exit code 1
In Scastie, I get the following warnings, but not errors, which I don’t understand the meaning of.
non-variable type argument (B, B) in type pattern List[(B, B)] (the underlying of List[(B, B)]) is unchecked since it is eliminated by erasure
abstract type B in type pattern Option[B] is unchecked since it is eliminated by erasure