当前位置:网站首页>Kotlin classes and objects
Kotlin classes and objects
2022-07-04 19:41:00 【AdleyTales】
import java.util.*
// Class contains constructors 、 Initialize code block 、 function 、 attribute 、 Inner class 、 Object declaration
// Non empty properties must be initialized at the time of definition ,kotlin Provides a way to delay initialization , Use lateinit Keyword description properties
class People {
// The properties of a class can use keywords var Declare variable , Otherwise, use read-only keywords val Declared immutable
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 ------")
}
// Member functions
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()
}
边栏推荐
猜你喜欢
Oracle with as ORA-00903: invalid table name 多表报错
一文掌握数仓中auto analyze的使用
Chrome开发工具:VMxxx文件是什么鬼
欧拉函数
BCG 使用之新建向导效果
JVM系列之对象的创建
PolyFit软件介绍
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
西门子HMI下载时提示缺少面板映像解决方案
Euler function
随机推荐
Hough transform Hough transform principle
Online text line fixed length fill tool
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
在线文本行固定长度填充工具
Niuke Xiaobai month race 7 F question
Cbcgpprogressdlgctrl progress bar used by BCG
Shell programming core technology "three"
1009 product of polynomials (25 points) (PAT class a)
Detailed explanation of the binary processing function threshold() of opencv
Oracle with as ORA-00903: invalid table name 多表报错
To sort out messy header files, I use include what you use
升级智能开关,“零火版”、“单火”接线方式差异有多大?
《工作、消费主义和新穷人》的微信读书笔记
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
矩阵翻转(数组模拟)
Pytorch学习(四)
How test engineers "attack the city" (Part 2)
Allure of pytest visual test report
Several methods of online database migration
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)