jhonsef
01/12/2018, 4:07 PMilya.gorbunov
01/13/2018, 4:29 AMpath
list every time to the results
list. Then you're mutating it, eventually clearing it.Jordy Langen
01/13/2018, 10:34 AMdimcha
01/13/2018, 4:21 PM// Java class
public class BaseOne {
public static void m1() {
System.out.println("BaseOne");
}
}
// redefined method in child _java_ class
public class BaseThree extends BaseOne {
public static void m1() {
System.out.println("BaseThree");
}
}
// Kotlin
class BaseTwo : BaseOne() {
companion object {
fun m1() { // Error raises here :(
println("BaseTwo")
}
}
}
andyfleming
01/14/2018, 8:46 AMarekolek
01/14/2018, 12:07 PMfun <T> LiveData<T>.distinct(): LiveData<T> {
var lastValue: Any? = Any()
return MediatorLiveData<T>().apply {
addSource(this@distinct) {
if (it != lastValue) {
lastValue = it
postValue(it)
}
}
}
}
Or using a property of the object:
fun <T> LiveData<T>.distinct(): LiveData<T> {
return MediatorLiveData<T>().apply {
addSource(this@distinct, object : Observer<T> {
private var lastValue: Any? = Any()
override fun onChanged(value: T?) {
if (value != lastValue) {
lastValue = value
postValue(value)
}
}
})
}
}
Any arguments to prefer one over the other?tschuchort
01/14/2018, 2:47 PMlouiscad
01/14/2018, 11:10 PMpoohbar
01/15/2018, 3:06 AMedwardwongtl
01/15/2018, 3:33 AMlateinit var
is initialised or not, is that out already?dominik.sittel
01/15/2018, 6:59 AMrootandy
01/15/2018, 10:59 AMg4sarma
01/15/2018, 1:12 PMJimmy Alvarez
01/15/2018, 2:26 PMmenegatti
01/15/2018, 4:08 PMralf
01/15/2018, 5:06 PMe: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor cannot be cast to org.jetbrains.kotlin.codegen.AccessorForPropertyBackingField
Cause: org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor cannot be cast to org.jetbrains.kotlin.codegen.AccessorForPropertyBackingField
File being compiled and position: (48,33) in /Users/rwondratschek/dev/projects/evernote/evernote/libs/style/fonts/src/main/kotlin/com/evernote/android/font/EvernoteFont.kt
PsiElement: isInitialized
The root cause was thrown at: ExpressionCodegen.java:1974
private lateinit var typeface: Typeface
fun getTypeface(context: Context): Typeface {
if (!::typeface.isInitialized) {
synchronized(this) {
// if (!::typeface.isInitialized) {
typeface = try {
if (fontRes >= 0) {
ResourcesCompat.getFont(context, fontRes) ?: Typeface.DEFAULT
} else {
Typeface.create(context.getString(stringFontRes), style)
}
} catch (t: Throwable) {
Log.e("Font", "Couldn't load font $this", t)
Typeface.DEFAULT
}
// }
}
}
return typeface
}
leus
01/15/2018, 6:26 PMcedric
01/16/2018, 4:12 AMbj0
01/16/2018, 4:25 AMwith
to scope extension functions/properties defined in an object
, but thats about allrobstoll
01/16/2018, 10:12 AMjstuyts-squins
01/16/2018, 10:16 AMcb
is indeed Any
, but I can still access framebufferSize
. This is in a JVM module (apply plugin: 'kotlin'
) of a multi-platform project using Kotlin 1.2.10:
val cb = object {
val framebufferSize = 1
}
println(cb.framebufferSize)
Dier
01/16/2018, 11:18 AMziggy42
01/16/2018, 2:25 PMJimmy Alvarez
01/16/2018, 3:40 PMmikaelhg
01/16/2018, 4:45 PMcedric
01/16/2018, 8:53 PMapply
returns the receiver while with
returns the last expression of the block. Different uses.gildor
01/17/2018, 1:42 AM==
instead of elvis operator for nullable booleans:
it?.equals(obj) ?: false || it == obj
-> it?.equals(obj) == true || it == obj
StavFX
01/17/2018, 1:57 AMit == obj
- the only caveat is that if it
and obj
are both null
- you'll get true
.
If that's not desired, then this would yield the same result as the original code it != null && it == obj
Ayden
01/17/2018, 2:42 AM0, 1, 4, 9, 16
.Ayden
01/17/2018, 2:53 AMval x: IntArray = intArrayOf(1, 2, 3)
val x = Array(3, {i -> i + 1})