Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * We declare a package-level function main which returns Unit and takes
- * an Array of strings as a parameter. Note that semicolons are optional.
- */
- fun main(args: Array<String>) {
- println("Hello, world!")
- funLiteral( {x,y ->
- a() // 可以调用Test里的方法
- println("This is func varieble")
- b()
- })
- println(sum(1, 2))
- }
- fun funLiteral(func: Test.(x: Int , y: Int) -> Unit) {
- val tmp = Test()
- tmp.func(1, 2) // 相当于给Test增加了实例方法func
- }
- class Test {
- fun a() {
- println("This is func a")
- }
- fun b() {
- println("This is func b")
- }
- }
Add Comment
Please, Sign In to add comment