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)
       
      }
     
    }

  • 相关阅读:
    Qt共享内存实现进程间通信(QSharedMemory)
    Qt5.5制作简单的屏幕截图程序
    006--C++动态内存(简介)
    005--C++字符
    004--C++11的初始化方式
    003--sizeof的使用
    002--C++程序的创建
    001--基础知识准备
    Qt5.5连接MySQL
    vue-cli中如何创建并引入自定义组件
  • 原文地址:https://www.cnblogs.com/mengyao/p/4651987.html
Copyright © 2011-2022 走看看