Skip to content

Instantly share code, notes, and snippets.

View akexorcist's full-sized avatar
🔥

Akexorcist akexorcist

🔥
View GitHub Profile
// Not Null
val user : User = ...
user.apply {
...
}
// Nullable
val user : User? = ...
user?.apply {
...
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")
fun startHere() {
var addResult = calculate(10, 3, { x, y ->
x + y
})
var subtractResult = calculate(10, 3, { x, y ->
x - y
})
...
}
fun doSomething() {
...
doComplexTask("Akexorcist", { name ->
"Mr.${name.trim()}"
}, { fullName ->
System.out.println("Hello, $fullName")
})
}
fun doComplexTask(name: String,
method1: (name: String) -> String,
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
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();
}
for (index in 1..100) {
var addResult = calculate(10, index, { x, y ->
x + y
})
...
}
fun startHere() {
for (index in 0..100) {
var addResult = calculate(10, index, { x, y ->
x + y
})
...
}
}
inline fun calculate(x: Int,
y: Int,