zoukankan      html  css  js  c++  java
  • Scala路径依赖【内部类】

     1 package big.data.analyse.scala.path_dependence
     2 
     3 /**
     4   * 路径依赖
     5   * Created by zhen on 2018/12/24.
     6   */
     7 // 定义外部类,内部类
     8 class Outer(val  Int, val height : Int){
     9   //private val width = 12
    10   //private val height = 6
    11 
    12   class Inner{
    13     private val space = width * height
    14 
    15     def show(): Unit ={
    16       println(" the space is equal : " + space)
    17     }
    18   }
    19 }
    20 object PathDependence {
    21   def main(args: Array[String]) {
    22     val outer = new Outer(6, 8)
    23     val inner = new outer.Inner
    24     inner.show()
    25     // 特定类型的内部类
    26     val inner_belong_outer : outer.Inner = new outer.Inner
    27     inner_belong_outer.show()
    28 
    29     val another_other = new Outer(3, 4)
    30     //val another_inner : outer.Inner = new another_other.Inner // Inner doesn't conform
    31     val use_inner : Outer#Inner = new another_other.Inner // # 表示Inner是Outer的内部类
    32     use_inner.show()
    33 
    34   }
    35 }

    结果:

  • 相关阅读:
    nodeJs-querystring 模块
    nodeJs-process对象
    nodejs-Path模块
    nodejs-os模块
    nodejs-CommonJS规范
    nodejs-Events模块
    nodejs-Http模块
    nodejs-Cluster模块
    转:AOP与JAVA动态代理
    转:jdk动态代理实现
  • 原文地址:https://www.cnblogs.com/yszd/p/10173755.html
Copyright © 2011-2022 走看看