matanox
matanox

Reputation: 13686

Can you directly pass a non-implicit val as argument to a function expecting an implicit?

Excuse the mind blank.

class Bar(implicit foo: Foo)

class Foo {
  implicit val self = this 
  lazy val bar = new Bar
}

Can we simplify the instantiation of Bar to a single statement where this is provided very explicitly as the constructor argument?

My question also applies to passing any val, not only a this as in this example.

Upvotes: 3

Views: 50

Answers (1)

Thilo
Thilo

Reputation: 262464

The implicit parameter in your constructor is part of the second set of parameters here (the first set is empty), so you can do

val bar = new Bar()(new Foo)

Upvotes: 3

Related Questions