最高的父类型为Any,最低类型为Nothing

Any is the supertype of all types, also called the top type. It defines certain universal methods such as equalshashCode, and toStringAny has two direct subclasses: AnyVal and AnyRef

注意:hashCode,equals,toString方法在Any类型中

AnyVal represents value types.

There are nine predefined value types and they are non-nullable: DoubleFloatLongIntShortByteCharUnit, and BooleanUnit is a value type which carries no meaningful information. There is exactly one instance of Unit which can be declared literally like so: (). All functions must return something so sometimes Unit is a useful return type

值类型是不能为null,Unit代表不携带任何有意义的信息

//test AnyVal is not null-able
//compile error
//error msg an expression of type Null is ineligible for implicit conversion
val xi :Int = null

 

AnyRef represents reference types. All non-value types are defined as reference types. Every user-defined type in Scala is a subtype of AnyRef. If Scala is used in the context of a Java runtime environment, AnyRef corresponds to java.lang.Object

//AnyRef在Java运行环境中相当于java.lang.Object

类型转换

val x: Long = 987654321
val y: Float = x // 9.8765434E8 (note that some precision is lost in this case) val face: Char = '☺'
val number: Int = face // 9786

  Casting is unidirectional. This will not compile

类型转换未按照图中的方向,不编译.

意思就是scala类型转换一定是安全的.不能由长类型转成短类型(这句话或许有错,因为Long可以转换成Float)

Char不能到Long应该是scala的编译不能识别这种转换,以后在爬这个事的原因

val x: Long = 987654321
val y: Float = x // 9.8765434E8
val z: Long = y // Does not conform

  

Nothing is a subtype of all types, also called the bottom type. There is no value that has type Nothing. A common use is to signal non-termination such as a thrown exception, program exit, or an infinite loop (i.e., it is the type of an expression which does not evaluate to a value, or a method that does not return normally).

Null is a subtype of all reference types (i.e. any subtype of AnyRef). It has a single value identified by the keyword literal nullNull is provided mostly for interoperability with other JVM languages and should almost never be used in Scala code. We’ll cover alternatives to null later in the tour.

Null在scala中用null代替,为了保证scala和其他Java虚拟机语言的互操作性

scala变量类型和性质的更多相关文章

  1. Scala变量(三)

    变量是一种使用方便的占位符,用于引用计算机内存地址,变量创建后会占用一定的内存空间. 基于变量的数据类型,操作系统会进行内存分配并且决定什么将被储存在保留内存中.因此,通过给变量分配不同的数据类型,你 ...

  2. 20151010 C# 第一篇 变量类型

    20151010 变量类型: 1. 值类型:变量本身直接存储数据 整数类型:代表没有小数点的整数数值 类型 说明 范围 sbyte 8位有符号整数 -128——127 short 16位有符号整数 - ...

  3. Scala基础类型与操作

    Scala基本类型及操作.程序控制结构 Scala基本类型及操作.程序控制结构 (一)Scala语言优势 自身语言特点: 纯面向对象编程的语言 函数式编程语言 函数式编程语言语言应该支持以下特性: 高 ...

  4. Scala变量| 流程控制

    Scala 是 Scalable Language 的简写,是一门多范式(编程的方式)的编程语言 Scala是一门以java虚拟机(JVM)为目标运行环境并将面向对象和函数式编程的最佳特性结合在一起的 ...

  5. 2. Scala变量

    2.1 变量是程序的基本组成单位 举一个简单的例子 object boke_demo01 { def main(args: Array[String]): Unit = { var a: Int = ...

  6. Spark记录-Scala变量/访问修饰符/运算符

    变量是保存存储值的内存位置的名称.这意味着当创建变量时,可以在内存中保留一些空间. 根据变量的数据类型,编译器分配内存并决定可以存储在预留内存中的内容.因此,通过为变量分配不同的数据类型,可以在这些变 ...

  7. Scala系统学习(四):Scala变量

    变量是保存存储值的内存位置的名称.这意味着当创建变量时,可以在内存中保留一些空间. 根据变量的数据类型,编译器分配内存并决定可以存储在预留内存中的内容.因此,通过为变量分配不同的数据类型,可以在这些变 ...

  8. C的变量类型、作用域与生命周期的总结

    C的变量类型.作用域与生命周期的总结 最近在看"C Programing Language" (Kernighan, Ritchie)关于外部变量的讨论,之前在学C的时候对这些ex ...

  9. Scala 基础(四):Scala变量 (一) 基础

    1.概念 变量相当于内存中一个数据存储空间的表示,你可以把变量看做是一个房间的门 牌号,通过门牌号我们可以找到房间,而通过变量名可以访问到变量(值). 2 变量使用的基本步骤 1) 声明/定义变量 ( ...

随机推荐

  1. mha error

    MasterFailover.pm 1473 $ret =1474 $_server_manager->change_master_and_start_slave( $target, $late ...

  2. 单进程与 多进程关系及区别(多进程系统linux)

    单进程编程:顺序执行 数据同步 复杂度低 用途单一 多进程编程:同时执行 数据异步 复杂度高 用途广泛 1. 多进程的优势在于任务的独立性,比如某个任务单独作为一个进程的话,崩溃只影响自己的服务,其他 ...

  3. Thinkphp自定义标签

    1.定义TagLib目录和文件  TagLibSmarTop.class.php 2.配置文件 <?php return array( 'APP_AUTOLOAD_PATH'=>'@.Ta ...

  4. Azure Application Gateway (5) Application Gateway SSL Offload配置

    <Windows Azure Platform 系列文章目录> 之前有个客户提出了一个需求,他们的互联网访问的架构分为两种: 1.第一层是使用Azure Application Gatew ...

  5. 恢复word中审阅选项卡

    碰到在Word中,使用自定义功能区添加审阅选项卡,仍然不显示审阅选项卡 二个办法: 1.检查COM加载项,找出并从此禁用,如:iWebOffice2009.ocx 2.创建自定选项卡“审阅(自定义)” ...

  6. python中pip和pygame的安装

    1.安装pip和pygame都很简单.首先咱们来安装pip,官网https://pypi.python.org/pypi/pip#download,下载pip的压缩文件,并将其解压. 我们在cmd的p ...

  7. web环境中微信JS-SDK配置

    一.公众号相关设置 首先,在公众号中进行JS安全域名的设置,在公众号设置-功能设置中选择JS接口安全域名,点击设置进入设置对话框.按照要求逐步进行,完成设置. 二.页面请求发送与处理 引入所需js: ...

  8. mysql查询优化之一:mysql查询优化常用方式

    一.为什么查询速度会慢? 一个查询的生命周期大致可以按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中在“执行”阶段包含了大量为了检索数据到存储引擎 ...

  9. 学习笔记之The Intelligent Investor, Rev. Ed

    The Intelligent Investor, Rev. Ed https://www.safaribooksonline.com/library/view/the-intelligent-inv ...

  10. [UE4]虚幻4链接独立服务器

    如果虚幻4只做客户端的话,应该怎么连接服务器呢? 官方并没有提供蓝图的网络函数,C++里面有. 一.自己实现,提供接口给蓝图使用. 二.第三方插件.插件下载地址:https://github.com/ ...