This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Not Null | |
| val user : User = ... | |
| user.apply { | |
| ... | |
| } | |
| // Nullable | |
| val user : User? = ... | |
| user?.apply { | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val user : User? = null | |
| val result = user?.let { | |
| ... | |
| } | |
| // result = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val user : User? = null | |
| val result = user?.apply { | |
| ... | |
| }?.also { | |
| ... | |
| }?.run { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun startHere() { | |
| doAnything { | |
| System.out.println("Do something before 2nd thing") | |
| } | |
| } | |
| fun doAnything(block: () -> Unit) { | |
| System.out.println("Do 1st thing") | |
| block() | |
| System.out.println("Do 2nd thing") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun startHere() { | |
| var addResult = calculate(10, 3, { x, y -> | |
| x + y | |
| }) | |
| var subtractResult = calculate(10, 3, { x, y -> | |
| x - y | |
| }) | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun doSomething() { | |
| ... | |
| doComplexTask("Akexorcist", { name -> | |
| "Mr.${name.trim()}" | |
| }, { fullName -> | |
| System.out.println("Hello, $fullName") | |
| }) | |
| } | |
| fun doComplexTask(name: String, | |
| method1: (name: String) -> String, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun startHere() { | |
| var addResult = calculate(10, 3, { x, y -> | |
| x + y | |
| }) | |
| ... | |
| } | |
| fun calculate(x: Int, | |
| y: Int, | |
| equation: (x: Int, y: Int) -> Int): Int { | |
| // Do something |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final void startHere() { | |
| int addResult = this.calculate(10, 3, (Function2)null.INSTANCE); | |
| ... | |
| } | |
| public final int calculate(int x, int y, @NotNull Function2 equation) { | |
| Intrinsics.checkParameterIsNotNull(equation, "equation"); | |
| // Do something | |
| return ((Number)equation.invoke(x, y)).intValue(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (index in 1..100) { | |
| var addResult = calculate(10, index, { x, y -> | |
| x + y | |
| }) | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun startHere() { | |
| for (index in 0..100) { | |
| var addResult = calculate(10, index, { x, y -> | |
| x + y | |
| }) | |
| ... | |
| } | |
| } | |
| inline fun calculate(x: Int, | |
| y: Int, |