Skip to content

Instantly share code, notes, and snippets.

View osualaFC's full-sized avatar

Fredrick Chibuzor Osuala osualaFC

View GitHub Profile

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

@osualaFC
osualaFC / fadeTo.kt
Created April 1, 2021 13:00 — forked from gpeal/fadeTo.kt
Fade To
/**
* Fade a view to visible or gone. This function is idempotent - it can be called over and over again with the same
* value without affecting an in-progress animation.
*/
fun View.fadeTo(visible: Boolean, duration: Long = 500, startDelay: Long = 0, toAlpha: Float = 1f) {
// Make this idempotent.
val tagKey = "fadeTo".hashCode()
if (visible == isVisible && animation == null && getTag(tagKey) == null) return
if (getTag(tagKey) == visible) return
import timber.log.Timber
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class MyClass {
// This will automatically have the TAG "MyClass"
private val log by timber()
fun logSomething() {
log.i("Hello")
{
pokemon: [
{
id: 1,
num: "001",
name: "Bulbasaur",
img: "http://www.serebii.net/pokemongo/pokemon/001.png",
type: [
"Grass",
"Poison"