Kevin Meredith
Kevin Meredith

Reputation: 41909

Difference between Traits?

Is there any difference between these two trait's?

scala> trait Bar[A <: Foo] {
     |    def bippy(x: A): A
     | }
defined trait Bar

and

scala> trait BarTwo {
     |   type A <: Foo
     |
     |   def bippy(x: A): A
     | }
defined trait BarTwo

EDIT:

The difference in their names is not a meaningful difference per my question. I'm looking for any difference between these two trait constructs.

Upvotes: 4

Views: 67

Answers (1)

Daniel Langdon
Daniel Langdon

Reputation: 5999

In most practical cases, there is no difference, and as @AkosKrivachy commented, they are scheduled to be made completely equivalent. Nevertheless, while the official documentation states that

it is often possible to turn abstract type members into type parameters of classes and vice versa.

It also states at the end that

Furthermore, there are cases where it is not possible to replace abstract types with type parameters.

Sadly, I could not find any description of what those cases are :-(

I'm posting this as an answer in case given that a better answer might not be forthcoming and you might want to close this, but let's hope.

Upvotes: 1

Related Questions