Guest User

Untitled

a guest
Feb 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. /**
  2. * We declare a package-level function main which returns Unit and takes
  3. * an Array of strings as a parameter. Note that semicolons are optional.
  4. */
  5.  
  6. fun main(args: Array<String>) {
  7. println("Hello, world!")
  8. funLiteral( {x,y ->
  9. a() // 可以调用Test里的方法
  10. println("This is func varieble")
  11. b()
  12. })
  13. println(sum(1, 2))
  14. }
  15.  
  16. fun funLiteral(func: Test.(x: Int , y: Int) -> Unit) {
  17. val tmp = Test()
  18. tmp.func(1, 2) // 相当于给Test增加了实例方法func
  19. }
  20.  
  21. class Test {
  22. fun a() {
  23. println("This is func a")
  24. }
  25.  
  26. fun b() {
  27. println("This is func b")
  28. }
  29. }
Add Comment
Please, Sign In to add comment