One problem I continually run into scala is with lambda' expressions. For instance
JarBuilder.findContainingJar(clazz).foreach {userJars = userJars + _ }
gives me an error like:
missing parameter type for expanded function ((x$1) => userJars.$plus(x$1))
Yet if I do the expansion myself:
JarBuilder.findContainingJar(clazz).foreach {x => userJars = userJars + x }
It works fine.
Is this a Scala bug? Or am I doing something horribly wrong?
The usage of placeholder syntax for anonymous functions is restricted to expressions. In your code you are attempting to use the wildcard in an assignment statement which is not the same as an expression.
If you look closely at the error, you can see that the expression on the right hand side of your assignment is what is being expanded into an anonymous function.
Given what you are trying to accomplish however you may want to consider the following
userJars = userJars ++ JarBuilder.findContainingJar(clazz)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With