class InfoEnty(var x:Int,var y:Int){
// 嵌套类、内部类
class Info(var name:String){
fun show()= println("装备:$name")
}
fun batter(){
Info("偃月刀").show()
}
// 运算符重载 "+-"对应的关键字是:plus
// "=="是equse,"=="比较的是内容,不是引用(不是同一个对象);
operator fun plus(other:InfoEnty)=InfoEnty(x+other.x,y+other.y)
}
//
/**
*
* 数据类
*
* 1、数据类(关键字:data)中"=="是比较数值是否相当,并不是指同一个引用
*
*
* 2、重写了tostring方法
* 3、copy方法,可以复制类,并且传参改变该对象的属性值;
* 4、解构语法
*
* 数据类不能是抽象,被继承、密封
*
* 字符串创建的经典面试题
* 为什么重写equse方法要重写hashcode方法
* 因为数据类的比较去重是数据上的,也就是说,数据值都相等,那就相等,不用考虑它是否是内存中 的同一个对象
* 当两个对象equse为true时,它的hashcode应该也相等
* */
/**
* 运算符重载
*
* */
fun main(args: Array<String>) {
// 内部类,镶嵌类
InfoEnty(0,0).batter()
var code1=InfoEnty(1,1)
var code2=InfoEnty(2,2)
var code3=code1+code2//运算符重载
}
/**
* 枚举类
* */
enum class LicenseStatus{
UNQUALIFIFD,
LEARNING,
QUALIFIFD
}
/**
* 代数数据类型ADT
* */
class Dirvar(var status:LicenseStatus){
fun checkLicense():String{
return when(status){
LicenseStatus.UNQUALIFIFD->"没资格"
LicenseStatus.LEARNING->"正在学习"
LicenseStatus.QUALIFIFD->"通过"
}
}
}