当前位置:网站首页>kotlin 类和对象
kotlin 类和对象
2022-07-04 18:32:00 【AdleyTales】
import java.util.*
// 类包含构造函数、初始化代码块、函数、属性、内部类、对象声明
// 非空属性必须在定义的时候初始化,kotlin提供了一种可以延迟初始化的方案,使用 lateinit 关键字描述属性
class People {
// 类的属性可以用关键字 var 声明为可变的,否则使用只读关键字 val 声明为不可变
var name: String = ""
var age: Int = 0
var addr: String = ""
get() = field.uppercase()
set(value) {
field = "G+$value"
}
constructor(name: String, age: Int, addr: String) {
this.name = name
this.age = age
this.addr = addr
println("constructor------")
}
constructor(name: String, age: Int) {
this.name = name
this.age = age
}
init {
println("init ------")
}
// 成员函数
fun foo() {
println("foo ---")
}
fun info() {
println("name: $name, age: $age, addr: $addr")
}
}
fun main() {
val p = People("adleytales", 19, "Beijing")
p.foo()
p.info()
p.name = "adley"
p.age = 18
p.info()
}
边栏推荐
- Wechat reading notes of "work, consumerism and the new poor"
- Use canal and rocketmq to listen to MySQL binlog logs
- Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
- Shell programming core technology "four"
- Pointnet/Pointnet++点云数据集处理并训练
- Educational Codeforces Round 22 E. Army Creation
- Shell 编程核心技术《四》
- Generate XML elements
- Opencv functions and methods related to binary threshold processing are summarized for comparison and use
- Have you guys ever used CDC direct Mysql to Clickhouse
猜你喜欢
MySQL数据库基本操作-DDL | 黑马程序员
Swagger突然发癫
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
BCG 使用之新建向导效果
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
在线文本行固定长度填充工具
随机推荐
Wechat reading notes of "work, consumerism and the new poor"
牛客小白月赛7 F题
BI技巧丨权限轴
The 300th weekly match of leetcode (20220703)
在线SQL转Excel(xls/xlsx)工具
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Stream stream
HDU 1097 A hard puzzle
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
Stream流
Shell programming core technology II
2019年蜀山区第十五届青少年信息学竞赛
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
线上数据库迁移的几种方法
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
TCP两次挥手,你见过吗?那四次握手呢?
ftp、sftp文件传输
Shell 编程核心技术《一》