KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I would like to have a sealed trait which have a declared method that returns the actual class that extends the trait. Should I use an abstract type, a parameter type or is there any other nice way to solve this? sealed trait Foo { type T def doit(other: T): T } or sealed trait Foo[T] { def doit(other: T): T } Note that T must be a subtype of Foo in this example. If I do it like this the type information feels too repeated: case class Bar(name: String) extends Foo[Bar] { def doit(other: Bar): Bar = ... }
Tags (comma-separated)
Save Edits
Cancel