今日学习:《机器学习十讲》第七讲,Scala。
后续可能还会进行补充。
Scala:cmd窗口相关操作。
val 与 var区别在于能否重新赋值,因此可以通过赋值判断
字符串相乘:
Max用法:
BigInt计算大数
首尾字符取法
Unit,Null与Nothing
package com.chapter01.datatype object UnitNullNothing { def main(args: Array[String]): Unit = { var res = sayHello() println("res=" + res) } //Unit等价于void,只有一个实例值,写作() def sayHello(): Unit = { } //Null只有一个实例对象null,类似于Java中的Null引用,它可以赋值给任意引用类型(AnyRef),但不能赋值给AnyVal var dog: Dog = null //var char1: Char = null 编写语句时不会报错,但运行时会报错。 //运行顺序是从上到下,先读到了sayHello先输出,再输出OK println("OK") } class Dog{ }
Nothing通常用来抛出异常。