score:71
Explanation is kind of unexpected: print
has a parameter named x
. Using x = ...
uses the named argument, therefore print(x="Hello World")
is the same as print("Hello World")
.
See Scala Predef docs or Predef.scala source:
object Predef /*....*/ {
/*....*/
def print(x: Any) = Console.print(x)
/*....*/
}
Note: this was already discussed in Scala Internal mailing list:
Scala currently tries to be smart about treating "x = e" as a named argument or an assignment ... This can be surprising to the user ....
Proposal: we deprecate assignments in argument lists
There also exists an issue SI-8206 for this, the change was probably implemented in issue 426 for Scala 2.13.
Your code will still compile after deprecation, with the same meaning. The change will be no one (at least no one sufficiently familiar with the language specs / implementation) should expect it to be interpreted as assignment any more.
Source: stackoverflow.com
Related Query
- Why is this Scala code with assignment of a val in a parameter working?
- Why does a small change to this Scala code make such a huge difference to performance?
- Why do I get 'Dead code following this construct' with the following code?
- Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?
- Why this scala code reports compilation error: recursive value x needs type
- Why this Scala code execute two Futures in one thread?
- Why is this scala code not inferring type?
- Why is this Scala example of implicit parameter not working?
- Why can't Scala infer the type parameter in this example?
- Why is this Scala code slow?
- Why does this Scala code throw IllegalAccessError at runtime?
- Why scala does not unify this type lambda with underlying type?
- Why does this code typecheck in Scala 2.11 and what can I do about it?
- Why can I call += with a single parameter on a Scala Set?
- why does this scala by-name parameter behave weirdly
- val cond: (Int, Int) => Boolean = (...) what does this scala code mean?
- Why implicit parameter not working when combined with non implicit parameter
- Why does a scala val definition with a dot in it produce an error in a later stage than parsing?
- Why Intellij's debugger hits breakpoint twice for this Scala code
- Why does this snippet with pattern matching and higher kinded types no longer compile in Scala 2.12?
- Why does this code with free monad interpreter compile?
- Why does the Scala compiler fail with missing parameter type for filter with JavaSparkContext?
- Scala Equality: Why does this code compile?
- Why scala serializability differs in case classes with same constructor parameter types?
- Why does this json4s code work in the scala repl but fail to compile?
- Why does this code work successfully with Enumerator.fromFile?
- Why is the each iteration parameter val and not var in for loop in scala
- Can anyone 1-line this Scala code (preferably with FP?)
- Why this scala code has a compilation error type mismatch
- Why scala cannot infer common return type for a function with multiple parameter lists?
More Query from same tag
- Spark Read JSON with Request Parameters
- Scala - How to convert a Dataset[Row] to a column that can be added to a Dataframe
- Dynamically query spark sql dataframe with complex type
- Scala mutable BitSet, where are the mutating operations?
- Scala how to check Unit for equality?
- How to avoid mutating of a state variable in an Akka actor with inherited behavior?
- How do I make an increaser for several variables?
- Akka Tcp create peer to peer architecture instead of client server
- Observable from Futures - onNext from multiple threads
- Spark - How to use SparkContext within classes?
- Why does reading CSV file fail in cluster mode (while works fine in local)?
- NoJson found on an http request on play 2.3.2
- when should lazy val be used rather than a function
- How to traverse List[IO] to execute everything and collect all errors?
- Scala create a function to run on existing type
- Scala actors, futures and system calls resulting in Thread leaks
- Convert Set[Strings] to JSON String scala
- Spark - use dataframe many times without many unloads
- How to connect to an Azure SQL Server using service principal in Scala
- Date and Timestamp serialization by Jackson ObjectMapper
- Can I define a table's ROW_FORMAT with Slick's Table class?
- How to replace a JSON value in Play
- Why isn't scala.util.Success.apply infinitely recursive?
- How to copy file from local to HDFS directory in Oozie spark scala job?
- Accessing only part of a list in Scala using .last
- Scala Play 2.5 Turning an Action into A Result
- dataframe with nested aggregation
- Akka Authentication with REST Http
- scala.ScalaReflectionException: <none> is not a term
- What is the difference between anonymous functions and partial functions?