This file contains 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
class R; |
This file contains 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
#include "rgbapixel.h" | |
/** | |
* This function constructs a default pixel which is opaque | |
* (non-transparent) and white. | |
**/ | |
RGBAPixel::RGBAPixel() | |
{ | |
alpha = 255; | |
red = 255; |
This file contains 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
{ | |
"coordinates": null, | |
"created_at": "Thu Oct 21 16:02:46 +0000 2010", | |
"favorited": false, | |
"truncated": false, | |
"id_str": "28039652140", | |
"entities": { | |
"urls": [ | |
{ | |
"expanded_url": null, |
This file contains 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 <T> observeUntilFinished(liveData: LiveData<T>, observer: Observer<T>? = null) { | |
liveData.observeForever(object : Observer<T> { | |
override fun onChanged(resource: Resource<T>?) { | |
observer?.onChanged(resource) | |
liveData.removeObserver(this) // SAM conversion is not applicable because of `this` | |
} | |
}) | |
} |
This file contains 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
@FunctionalInterface | |
public interface JavaSam { | |
boolean apply(@NotNull Integer id); | |
} |
This file contains 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
// JavaApp.java | |
private boolean isEven(int id) { | |
return id % 2 == 0; | |
} | |
public boolean invokeJavaSam(int id, JavaSam sam) { | |
return sam.apply(id); | |
} |
This file contains 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
// KotlinApp.kt | |
typealias KotlinFunction = (Int) -> Boolean | |
fun invokeKotlinFunction(id: Int, f: KotlinFunction) = f(id) | |
// JavaApp.java | |
private void useKotlinFunction() | |
Function1<Integer, Boolean> kotlinFunc = id -> id % 2 == 0; | |
KotlinAppKt.invokeKotlinFunction(3, id -> id % 2 == 0); | |
KotlinAppKt.invokeKotlinFunction(4, this::isEven); |
This file contains 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 isEven(id: Int) = id % 2 == 0 | |
fun invokeJavaSam(id: Int, sam: JavaSam) = sam.apply(id) | |
fun useJavaSam() { | |
val javaSam = JavaSam { id -> id % 2 == 0 } | |
invokeJavaSam(3, JavaSam { id -> id % 2 == 0 }) | |
invokeJavaSam(4, JavaSam { isEven(it) }) | |
// public boolean invokeJavaSam(int id, JavaSam sam); |
This file contains 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 invokeKotlinInterface(id: Int, i: KotlinInterface) = i.apply(id) | |
fun useKotlinInterface() { | |
val kotlinInterface = object : KotlinInterface { | |
override fun apply(id: Int) = id % 2 == 0 | |
} | |
invokeKotlinInterface(3, object : KotlinInterface { | |
override fun apply(id: Int) = id % 2 == 0 | |
}) | |
invokeKotlinInterface(4, object : KotlinInterface { |
This file contains 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 invokeKotlinFunction(id: Int, f: KotlinFunction) = f(id) | |
fun useKotlinFunction() { | |
val kotlinFunction : KotlinFunction = { id -> id % 2 == 0 } | |
invokeKotlinFunction(3) { id -> id % 2 == 0 } | |
invokeKotlinFunction(4) { isEven(it) } | |
invokeKotlinFunction(4, ::isEven) | |
} |
OlderNewer