Enter aliases for the external object as the private parameter of the scope

I have such a situation.

object SuperHorribleLongName { trait X { private[SuperHorribleLongName] def internalGaga() : Unit } } 

and I'm trying to do something like this:

 object SuperHorribleLongName { private type Sup = SuperHorribleLongName.type trait X { private[Sup] def internalGaga() : Unit } } 

but it just gives me the "error: Sup is not an enclosing class" ... I also tried type Sup = this.type , but still it doesn't work.

In any case, to create a bright label for my external object when using an area as a private parameter? I want to keep a long name for the object, and I have many private methods, so it really bothers me.

+4
source share
1 answer

I know this matches your hierarchy, but what about placing all your personal methods in

 private trait Y { 

Otherwise, you can always simulate a namespace:

 object SuperHorribleLongName { object SHLN { //Dummy alias trait X { private[SHLN] def internalGaga() : Unit } } type X = SHLN.X //Lift into main object } 

This is not satisfactory, since the SHLN is visible, and its private rotation prevents the rise of X. And this is messy.
So, include the problem inside / outside:

 private object SHLN { trait X { private[SHLN] def internalGaga() : Unit } } //Expose the instance under wanted name val SuperHorribleLongName = SHLN 
0
source

Source: https://habr.com/ru/post/1382741/


All Articles