score:51
with
means that the class is using a Trait via mixin.
Post
has the Trait IdPK
(similar to a Java class can implements
an Interface).
score:21
While this isn't a direct answer to the original question, it may be useful for future readers. From Wikipedia:
Scala allows to mix in a trait (creating an anonymous type) when creating a new instance of a class.
This means that with
is usable outside of the top line of a class definition. Example:
trait Swim {
def swim = println("Swimming!")
}
class Person
val p1 = new Person // A Person who can't swim
val p2 = new Person with Swim // A Person who can swim
p2
here has the method swim
available to it, while p1
does not. The real type of p2
is an "anonymous" one, namely Person with Swim
. In fact, with
syntax can be used in any type signature:
def swimThemAll(ps: Seq[Person with Swim]): Unit = {
ps.foreach(_.swim)
}
EDIT (2016 Oct 12): We've discovered a quirk. The following won't compile:
// each `x` has no swim method
def swim(xs: Seq[_ >: Person with Swim]): Unit = {
xs.foreach(_.swim)
}
Meaning that in terms of lexical precedence, with
binds eagerly. It's _ >: (Person with Swim)
, not (_ >: Person) with Swim
.
Source: stackoverflow.com
Related Query
- Scala with keyword usage
- 'with' keyword usage in scala with case classes
- Is there example of scala abstract type usage which is impossible to achieve with generics?
- pom configuration to force usage of jvm 7 with scala maven plugin
- Is it possible to make all values in scala object lazy with a single keyword
- Problem with a mutable Map in Scala with var keyword
- This keyword with scala and anonymous functions/classes
- Scala understanding memory usage with parallel collections
- Scala - Why should I define a Stream with the keyword lazy?
- Is there any video tutorial for setting up Scala IDE with usage of both external libraries and debugging your own source code projects dependencies?
- Can we use new keyword with scala traits
- Scala Option: Usage of unless with getOrElse
- Confused with usage of type parameter used in scala
- PlayFramework 2.4 Scala ActionRefiner with parameter from url usage
- What's the standard way to work with dates and times in Scala? Should I use Java types or there are native Scala alternatives?
- Why does the Scala compiler disallow overloaded methods with default arguments?
- Understanding what 'type' keyword does in Scala
- Debugging Scala code with simple-build-tool (sbt) and IntelliJ
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- Why does pattern matching in Scala not work with variables?
- "new" keyword in Scala
- Defining a function with multiple implicit arguments in Scala
- Efficient iteration with index in Scala
- Class broken error with Joda Time using Scala
- How to use third party libraries with Scala REPL?
- How to insert double quotes into String with interpolation in scala
- What is the forSome keyword in Scala for?
- Setting up scala with IntelliJ
- Asynchronous IO in Scala with futures
- Using Scala traits with implemented methods in Java
More Query from same tag
- How to use Status in own code in Play
- How to retrieve only words using regex
- Using `Seq::fill` with an existing sequence
- sbt-assembly behaviour with jars and Spark
- What data type should I use for tuple in Spark Dataframe udf?
- Creating some random case class dynamically using List[Strings] or Array[Strings]
- Check data type in Spark
- Parse ddMMMyy date string with regex in Scala
- How can I convert BinaryType to Array[Byte] when calling Scala UDF in Spark?
- Scala type parameter inference based on return type (function vs method)
- Large Negative Decimal Values are getting rounded in spark DataFrame with Decimal Type
- Unable to call any function on spark dataframe
- Spark ClassNotFoundException when run on yarn-cluster
- How to convert an Array of Array containing Integer to a Scala Spark List/Seq?
- Generating values programmatically scala
- Perform specialised functionality on failure of a Scalatest
- Custom version of fileUpload directive fails to materialize
- Why it evaluates to string?
- Implementing map on a tree using fold
- Scala statements and Expression - Var vs Val
- play framework 2: test a request with a json string as body
- How to extend the akka receive method in my current design
- Override whole class in java/scala
- Updating scala immutable SEQ with .map functionality
- MongoPasswordField setPassword + save
- Method with type parameter does not compile
- Fire action when two promises are complete
- Using Argonaut to create generic JSON converter
- Play Slick: How to fetch selected fields from a DB table in play-slick 3.0.0?
- Get a DateTime with an specific pattern with nscala-time