Referring to the type of an inner class in Scala

前端 未结 3 2087
攒了一身酷
攒了一身酷 2020-12-01 21:13

The following code tries to mimic Polymorphic Embedding of DSLs: rather than giving the behavior in Inner, it is encoded in the useInner method of

3条回答
  •  失恋的感觉
    2020-12-01 22:03

    I suppose the type Inner is like the type this.Inner. Outer#Inner is independent of the outer instance (not a path-dependent type).

    abstract class Outer {
      sealed class Inner {
        def enclosing = Outer.this
      }
      def useInner(x:Outer#Inner) : Boolean
    }
    
    def toBoolean(x:Outer#Inner) : Boolean = x.enclosing.useInner(x)
    

提交回复
热议问题