2. Hi, I am John
- Android Developer
- Work on Rakuten Viki
- Use Kotlin for 2 years
- Linkedin:
https://www.linkedin.com/in/chang-john-0a95237a/
3. Outline
- What’s a Function?
- Call a Function
- Anatomy of a Function
- Function Header
- Visibility Modifier
- Function Name declaration
- Function Return Type
- Function Body
4. Outline
- Named Functions v.s Anonymous Functions
- Function Type
- Implicit returns
- it keyword
- Function Inference Support
- High-Order Function
- Lambda/Function Reference/Anonymous Function
- Function Inlining
- Closure Behavior
- Function Support: Kotlin v.s Java
- Q&A
5. Q&A
- How to achieve backticks symbol naming?
- How Top level function in Kotlin is achieved on JVM?
- How default arguments in Kotlin is achieved on JVM?
- How naming function arguments in Kotlin is achieved on JVM?
- How to achieve Nothing type and TODO() function?
9. - Visibility modifier
- Use private/internal/public
- Without specify any visibility modifier, public is used by default
- Visibility Modifier definition
- Function Name
- Name by camel case with no underscores for convention.
- Surround using backticks symbol, like fun `This is my function`() { .. .}
- Function Parameters
- The Format is variableName: Type in order. No need to add val/var in advance.
- Default arguments, like fun log(tag: String = “”, msg: String) { … }
- Naming Function Arguments, like log(tag = “Main”, msg = “print function”)
11. - Return Type
- Return type can any type, primitive or class
- If no specify return type, default type is Unit
- Nothing type lets the compiler know that a function is guaranteed to NEVER successfully
complete, like TODO()