开发者

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

开发者 https://www.devze.com 2023-04-12 02:57 出处:网络
I have a trait that defines a single var and a single function like what follows: trait MyTrait { var myVar: Boolean

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

trait MyTrait {
  var myVar: Boolean

  def m开发者_JS百科yFunction = 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.


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

var myVar: Boolean = _
0

精彩评论

暂无评论...
验证码 换一张
取 消