如何举例说明Kotlin中class对象的实际应用?
- 内容介绍
- 文章标签
- 相关推荐
本文共计208个文字,预计阅读时间需要1分钟。
javaclass Person { void fly() { System.out.println(fly); } void walk() { System.out.println(walk); } void speak() { System.out.println(speak); } void jump() { System.out.println(jump); } void run() { System.out.println(run); } void eat() { System.out.println(eat); } void see() { System.out.println(see); } void think() { System.out.println(think); }}
class Person{
fun fly(){
println("fly");
}
fun walk(){
println("walk");
}
fun speak(){
println("speak");
}
fun jump(){
println("jump");
}
fun run(){
println("run");
}
fun eat(){
println("eat");
}
fun see(){
println("see");
}
fun think(): Person {
println("think");
return this;
}
fun listener(): Person {
println("listener");
return this;
}
}
var person=Person();
person.listener().think().see();
with(person){
eat()
think()
listener()
run()
fly()
}
listener
think
see
eat
think
listener
run
fly
上面的with可以在里面直接写方法,看起来高大上不过哈哈,然并卵的样子。
本文共计208个文字,预计阅读时间需要1分钟。
javaclass Person { void fly() { System.out.println(fly); } void walk() { System.out.println(walk); } void speak() { System.out.println(speak); } void jump() { System.out.println(jump); } void run() { System.out.println(run); } void eat() { System.out.println(eat); } void see() { System.out.println(see); } void think() { System.out.println(think); }}
class Person{
fun fly(){
println("fly");
}
fun walk(){
println("walk");
}
fun speak(){
println("speak");
}
fun jump(){
println("jump");
}
fun run(){
println("run");
}
fun eat(){
println("eat");
}
fun see(){
println("see");
}
fun think(): Person {
println("think");
return this;
}
fun listener(): Person {
println("listener");
return this;
}
}
var person=Person();
person.listener().think().see();
with(person){
eat()
think()
listener()
run()
fly()
}
listener
think
see
eat
think
listener
run
fly
上面的with可以在里面直接写方法,看起来高大上不过哈哈,然并卵的样子。

