Reputation: 55555
I am trying to create a variable of type MulticastLock, which is an inner class defined within the Android framework.
However, I am receiving an error stating that MulticastLock is not a member of WifiManager.
Do I need to reference an inner class differently in Scala?
var multicastLock:android.net.wifi.WifiManager.MulticastLock = null
Upvotes: 3
Views: 254
Reputation: 2829
In short, yes - you'll want to use #
instead of .
:
class A { class B }
val a : A.B = null
// error: not found: value A
val a : A#B = null
// works
The .
syntax is used to refer to members of a specific instance of the outer class:
val a = new A
val b : a.B = null
Upvotes: 3
Reputation: 167891
If WifiManager
is a class, then you need to use #
instead of .
. But be aware that this is not just an idle syntactic difference; when you have an inner class of an outer class, it can matter which instance of the outer class it came from. The #
alerts you to the fact that there is this new issue (X#Y
is the type of the inner class belonging to any copy, not a specific copy; if x
is an instance of X
, then x.Y
is the type of an inner class of that particular instance). There are other questions here that deal with different use cases of inner classes (e.g. Referring to the type of an inner class in Scala).
Upvotes: 6