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
interface CommunicationChannel { | |
@Throws(IOException::class) | |
fun connect(credentials: Credentials) | |
fun disconnect() | |
fun getChannelDescription(): Description | |
} |
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 List<String>.filterValid(): List<String> | |
@JvmName("filterValidInt") | |
fun List<Int>.filterValid(): List<Int> |
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
... | |
@JvmStatic fun newIntent(context: Context): Intent { | |
return Intent(context, SomeActivity::class.java) | |
} | |
/* Now you can omit Companion reference in Java: */ | |
Intent intent = SomeActivity.newIntent(context) |
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 SomeActivity : Activity() { | |
... | |
companion object { | |
fun newIntent(context: Context): Intent { | |
return Intent(context, SomeActivity::class.java) | |
} | |
} | |
} |
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
@file:JvmName("StringUtils") |
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
/* Method declared in StringExtensions.kt: */ | |
public inline fun String.capitalize(): String { | |
... | |
} | |
/* Will be translated into the following call in Java: */ | |
String lowercase = ... | |
String capitalized = StringExtensionsKt.capitalize(lowercase) |
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
@ExperimentalContracts | |
fun notNull(reference: Any?) { | |
contract { | |
returns() implies (reference != null) | |
} | |
if (reference == null) throw NullPointerException() | |
} | |
/* Now you can use the methid as follows: */ |
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 getLength(instance: Any): Int { | |
return if (instance is String) { | |
instance.length | |
} else if (instance is Text) { | |
instance.size() | |
} else { | |
0 | |
} | |
} |
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
public static <T> T checkNotNull(T reference) { | |
if (reference == null) { | |
throw new NullPointerException(); | |
} | |
return reference; | |
} |
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
launch(UI) { | |
val service = ... | |
val profile = service.getProfile() // background thread | |
view.showUserName(profile.name) // UI thread | |
finalizeOnboarding() // background thread | |
} |
NewerOlder