score:2
Accepted answer
Companion objects are objects like any other. In particular, they can extend traits as well. So you could have a trait for this secondary behavior.
trait Stage { ... }
trait StageCompanion {
def run(): Unit
}
class Write extends Stage { ... }
object Write extends StageCompanion {
override def run() = { ... }
}
And, of course, in your particular case, such a trait already exists: the Java interface Runnable
. So you could simply
object Write extends Runnable { ... }
Source: stackoverflow.com
Related Query
- Including Static Methods in Companion Objects when Extending from Traits
- How to "extend" factory methods when extending class with companion object with factory methods
- Override methods from traits in case objects
- calling methods of Controller from scala companion objects
- when to use Classes vs Objects vs Case Classes vs Traits
- How can I obtain Function objects from methods in Scala?
- Method in companion object compiled into static methods in scala?
- Calling different methods from different traits in scala with multiple inheritance
- How can I shield implementation level classes, traits and objects from Scala public APIs?
- Scala inherit from class with static methods
- How can I store a reference to a set of static Java methods from Scala?
- Inheritance of immutable return types when extending traits in multiple levels
- Scala 2.10 benchmark: generic methods from the collections are useless when performance is important?
- Accessing static methods of parameterized Java classes from Scala
- Difference in behavior with case objects extending traits
- Curly braces for `apply` method of companion objects of traits
- What does Singleton objects extending a superclass and mix in traits means?
- Calling methods from each other when using Abstact Class and Factory in Scala (Companion Object)
- switsh and helpSwitch methods missing from org.refcodes.console.ConsoleSugar when upgrading to 2.x
- Reflection does not see companion of subclass case class when defined in companion of extending trait
- Why methods of traits are called when a class has method's implementation
- PriorityQueue varargs error when extending Ordering to accomodate class objects
- Static Values in Traits Shared by Objects that Extend It
- Scala: methods in trait can't use methods from companion object
- Scala: Dynamically access companion objects from child classes
- Why the two apply methods in companion objects do not work?
- Scala & for comprehensions: Compile errors when implementing map, flatmap, and filter as instance methods that rely on a companion object
- Create companion objects for classes imported from Java
- When is an implicit imported from a companion object?
- How do I make a list of objects that descend from traits in Scala?
More Query from same tag
- Is Scala idiomatic coding style just a cool trap for writing inefficient code?
- Take string and extract first word and comma separate in scala?
- scala quasiquotes convert Tree to AppliedType
- Get _id from MongoDB using Scala
- Applying a map function to all elements of column in a Spark dataframe
- Scala implicit conversion on call-by-name parameter works differently depending on the function is overloaded or not
- How to parse a csv that uses ^A (i.e. \001) as the delimiter with spark-csv?
- Remove leading and trailing whitespaces between XML tags
- Implement MyMap (Higher Order Function) in Scala
- How to transform case class object graph to Map
- variables declared outside of while loop not accessible inside the while loop in scala
- Scala overloaded higher-order functions cause type error
- Type theory: type kinds
- Debug exceptions in AWT queue thread
- IntelliJ does not recognize symbols: Gradle, Scala, AWS
- How should I handle the html output generated in my Play 2 app by default helper or twitterBootstrap helper
- Pattern matching an int against a set of sets of ints
- Workflow and Scheduling Framework for Spark with Scala in Maven Done with Intellij IDEA
- IndexOutOfBounds Exception
- Saving contents of df.show() as a string in spark-scala app
- Annotating a function literal's implicit argument with a type
- case with an @ symbol in akka
- What's the equivalent of a python @classmethod or @staticmethod in Scala?
- BucketedRandomProjectionLSHModel approxNearestNeighbors function on entire dataframe
- IntelliJ IDEA 13 community edition with Scala
- Play framework akka stream websocket handling message get sent to deadletters
- How to check if message has sender in Akka Actor
- Multiple if else statements to get non-empty value from a map in Scala
- Read FASTQ file into a Spark dataframe
- Scala 2 macro type class derivation for `Coder[P <: Product]` ends with error `P does not take parameters`