geowa4
geowa4

Reputation: 41823

From Java, how can I access a var defined in a Scala trait?

I have a trait that defines a single var and a single function like what follows:

trait MyTrait {
  var myVar: Boolean

  def myFunction = 7
}

This trait is used by a class (let's say MyClass) and I'm using that class in a couple of Java files that I haven't converted yet. How, in my existing Java classes, can I access that variable? I can access the method just fine.

Upvotes: 0

Views: 88

Answers (1)

geowa4
geowa4

Reputation: 41823

Figured it out in one last attempt. If you initialize myVar it works as expected.

var myVar: Boolean = _

Upvotes: 1

Related Questions