I am trying to figure out how to create a method that takes a nested object as an argument. For a nested class I can do the following:
scala> class Outer {
| class Inner
| def method(i:Outer#Inner) = { "inner class" }
| }
defined class Outer
However, if I try something like that with an object instead i get an error:
scala> class Outer {
| object Inner
| def method(i:Outer#Inner) = { "inner object" }
| }
<console>:11: error: type Inner is not a member of Outer
def method(i:Outer#Inner) = { "inner object" }
What should the type of the argument to the method be to accomplish this? Also I want to refer to the type of Inner object not generalize the argument to say Any.
Inneris an object, thus it is not a type, and can’t be use as a type. the type ofInnerisInner.type. It means, in your example. Unfortunately, each instance of Outer will have it’s own Inner object and typeOuter#Inner.typecan not be used, since it is not stable. A workaround is to use:this.Inner.type.But it means that you can only pass as a parameter the Inner object of the instance on which you call
method.