Skip to content

Instantly share code, notes, and snippets.

View surajsau's full-sized avatar
🙇‍♂️
よろしくお願いします!

Suraj Kumar Sau surajsau

🙇‍♂️
よろしくお願いします!
View GitHub Profile
struct Person {
@CamelCase var name: String
}
@propertyWrapper
struct CamelCase {
var wrappedValue: String {
didSet { wrappedValue = wrappedValue.camelCase }
}
@surajsau
surajsau / CamelCase.kt
Created February 29, 2020 11:39
Camel case delegate in Kotlin
class Person {
var schoolName by CamelCased()
}
class CamelCased {
private var value: String = ""
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return value
@surajsau
surajsau / APIService.kt
Last active March 4, 2020 05:32
Neat representation of API calls in Retrofit
interface APIService {
// get all Star War films
@GET("/films")
fun getAllFilms(): Single<FilmListResponse>
// search for Starships
@GET("/starships")
fun getStarships(@Query("search") name: String): Single<StarshipListResponse>
//Kotlin
fun sample() {
val array = arrayOf(1, 2, 3, 4, 5)
array.forEachIndexed { index, item ->
print(item)
}
}
//Bytecode
public static final void sample() {
//Kotlin
fun checkMonsterName() {
val list = listOf(Monster("Nergigante"), Monster("Teostra"), Monster("Uragaan"))
val array = arrayOf(Monster("Nergigante"), Monster("Teostra"), Monster("Uragaan"))
list.forEach {
print(it.name)
}
//Kotlin
class Monster {
var level = 10
fun getName(hp: Int): String {
return when {
hp == 2 -> "Nergigante"
hp + 3 > 10 -> "Teostra"
hp < 0 -> "Jagras"
//Kotlin
class Person {
companion object {
@JvmField val JVM_FIELD_NAME = "John Doe"
const val CONST_NAME = "Josh Doe"
}
}
class Person {
companion object {
val NAME = "John Doe"
}
}
public final class Person {
@NotNull
//Kotlin
class Person {
companion object {
const val NAME = "John Doe"
}
}
//Bytecode
public final class Person {
@NotNull
//Kotlin
"(${input + 2}), ${if(input > 2) { "Hi" } else {"Bye"}}"
//Bytecode
(new StringBuilder()).append('(').append(input + 2).append("), ").append(input > 2 ? "Hi" : "Bye").toString();