Java: why do I receive the error message “Type mismatch: cannot convert int to byte”

Although the arithmetic operators are defined to operate on any numeric type, according the Java language specification (5.6.2 Binary Numeric Promotion), operands of type byte and short are automatically promoted to int before being handed to the operators. To perform arithmetic operations on variables of type byte or short, you must enclose the expression in … Read more

Composing Option with List in for-comprehension gives type mismatch depending on order

For comprehensions are converted into calls to the map or flatMap method. For example this one: for(x <- List(1) ; y <- List(1,2,3)) yield (x,y) becomes that: List(1).flatMap(x => List(1,2,3).map(y => (x,y))) Therefore, the first loop value (in this case, List(1)) will receive the flatMap method call. Since flatMap on a List returns another List, … Read more