score:75
Accepted answer
Yes they can, a trait
that extends a class
puts a restriction on what classes
can extend that trait
- namely, all classes
that mix-in that trait
must extend that class
.
scala> class Foo
defined class Foo
scala> trait FooTrait extends Foo
defined trait FooTrait
scala> val good = new Foo with FooTrait
good: Foo with FooTrait = $anon$1@773d3f62
scala> class Bar
defined class Bar
scala> val bad = new Bar with FooTrait
<console>:10: error: illegal inheritance; superclass Bar
is not a subclass of the superclass Foo
of the mixin trait FooTrait
val bad = new Bar with FooTrait
^
Source: stackoverflow.com
Related Query
- Why can a Scala trait extend a class?
- why I can update state of an Object extend immutable trait in scala
- Can a Scala class extend multiple classes?
- In scala is it possible for a trait to extend a class which needs parameters?
- Why scala class need to explicitly extend AnyRef
- Scala traits and structural types: can a trait extend a structural type and then call super?
- scala class extend a trait with generic which is a type of a field
- Scala collection class that can extend itself? AbstractSeq confusion
- how can i extend a type to a trait in scala
- Scala How can Trait override toString Case Class that is Derived Off
- Limiting classes that can extend a scala trait
- Make a class extend a generic trait in Scala
- How can I create a new specific type of class when extending a trait in scala
- How can two different class extend same class return same type in Scala
- why trait can extend abstract class?
- Can I dynamically construct a trait in Scala that is computed based on the class it extends?
- Force implementation of trait to provide an inner class that the trait can extend
- Why I can create instance of case class in scala without new operator?
- Why do case class companion objects extend FunctionN?
- Why to use empty parentheses in Scala if we can just use no parentheses to define a function which does not need any arguments?
- Why can't a class extend traits with method of the same signature?
- Why does Scala place a dollar sign at the end of class names?
- Why does Option not extend the Iterable trait directly?
- Can I use a scala class which implements a java interface from Java?
- Can I get a Scala case class definition from an Avro schema definition?
- If the Nothing type is at the bottom of the class hierarchy, why can I not call any conceivable method on it?
- Why can auxiliary constructors in Scala only consist of a single call to another constructor?
- Why not make every Scala class a case class?
- Why is scala list class named ::
- Can I override a scala class method with a method from a trait?
More Query from same tag
- How to load extra spark properties using --properties-file option in spark yarn cluster mode?
- Are there any plugins for generating API documentation for Play 2.x?
- Scala : How to pass a class field into a method
- Akka2.1/Scala - Nodes created in actor do not show up in context.children?
- how to redirect Scala Spark Dataset.show to log4j logger
- How do I "slow down" executing of tests in scala (transcation doesn't close in AfterExample)?
- Conditionally combine enumeratees
- How does one replace the trait IdPK with a custom trait that uses a String Primary Key instead of Long Primary Key?
- How to build an eclipse plugin with sbt and sbt-osgi?
- Scala Play - Some unresolved dependencies have extra attributes
- Scala: specify a default generic type instead of Nothing
- How to find most frequent string in List of strings
- SBT: How to run an annotation processing plugin
- Represent nested parameters for Neo4j query in Scala
- Multiple return points in scala closure/anonymous function
- YARN killing containers for exceeding memory limits
- What parameters do I pass to 'filter' function in Scala
- getOrElse for an Option(null) does not return a None type or the default value when null in Scala
- Play: Binary webservice response
- Spark Java Dataset classifying rows by range
- How to curry a function with one argument
- Use of underscore and map fuction in dataframes/scala
- Extractor object and class in Scala
- How to test a spray service
- Why does cats returns `Id[T]` in the evaluation of a Reader?
- java.util.Date inconsistent increment in scala
- Scope of 'spark.driver.maxResultSize'
- Is it possible to have a map of {key -> function call} in Scala?
- Trait A can only be extended by class that extends Trait B
- How to integrate Play (web framework), Deadbolt (authorization) and Slick (database access)