zoukankan      html  css  js  c++  java
  • Scala-变量、常量和懒加载

    package com.mengyao.scala.function

    /**
     * Scala的变量声明和使用(可变类型和值类型)
     *
     * @author mengyao
     */
    object Test0 {
     
      /**
       * Scala中的数据类型定义如下
       * @inline implicit def byteWrapper(x: Byte)       = new runtime.RichByte(x)
       * @inline implicit def shortWrapper(x: Short)     = new runtime.RichShort(x)
       * @inline implicit def intWrapper(x: Int)         = new runtime.RichInt(x)
       * @inline implicit def charWrapper(c: Char)       = new runtime.RichChar(c)
       * @inline implicit def longWrapper(x: Long)       = new runtime.RichLong(x)
       * @inline implicit def floatWrapper(x: Float)     = new runtime.RichFloat(x)
       * @inline implicit def doubleWrapper(x: Double)   = new runtime.RichDouble(x)
       * @inline implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x)
       *
       * Byte     8bit的有符号数字,范围在-128 -- 127
       * Short    16 bit有符号数字,范围在-32768 -- 32767
       * Int      32 bit 有符号数字,范围 -2147483648 到 2147483647
       * Long     64 bit 有符号数字,范围-9223372036854775808 到 9223372036854775807
       * Float    32 bit IEEE 754 单精度浮点数
       * Double   64 bit IEEE 754 双精度浮点数
       * Char     16 bit Unicode字符. 范围  U+0000 到 U+FFFF
       * String   字符串
       * Boolean  布尔类型
       * Unit     表示无值,和其他语言中void等同
       * Null     空值或者空引用
       * Nothing  所有其他类型的字类型,表示没有值
       * Any      所有类型的超类,任何实例都属于Any类型
       * AnyRef   所有引用类型的超类
       *
       */
     
      def main(args:Array[String]){
        
        //变量
        var a = 10
        println(a)
        
        //常量
        val b = "hello "+a;
        println(b)
        
        //获取最大值
        val c = Math.max(3, 1);
        println(c)
       
        //懒加载,在第一次使用时被初始化。没有用到时值为<lazy>
        lazy val d = "a"//在命令行中声明此变量,回车时显示d: String = <lazy>
        println(d)
       
      }
     
    }

  • 相关阅读:
    solaris 10 root忘记密码的解决方法
    c程序设计--指针与数组
    photoshop之色阶的使用
    Handling Errors Exceptionally Well in C++ 在C++中良好地捕获意外的错误
    自动换行 wordbreak:breakall和wordwrap:breakword
    透明度
    position:fixed在IE6下的实现
    JavaScript教程:常用DOM操作方法,JavaScriptDOM基本操作
    30 个免费的 UI 工具箱
    去掉虚线框兼容所有浏览器
  • 原文地址:https://www.cnblogs.com/mengyao/p/4651987.html
Copyright © 2011-2022 走看看