lupajz
02/06/2018, 5:10 PMtypealias foo = () -> Unit
cdurham
02/06/2018, 5:16 PMAlso note that this feature works only for Java interop; since Kotlin has proper function types, automatic conversion of functions into implementations of Kotlin interfaces is unnecessary and therefore unsupported.https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions
chb0kotlin
02/07/2018, 1:50 AMpublic class Foo {
private final Predicate<File> isChild = file -> file != null && (roots.contains(file) || this.isChild.test(file.getParentFile()));
}
And I have
class Foo {
private val isChild:(File) -> Boolean = { f -> roots.contains(f) || isChild(f.parentFile)}
}
The problem I am having is that it is saying 'isChild must be initialized' I don't get the same problem in java it's initialized with the instancekarelpeeters
02/07/2018, 1:51 AMlateinit
works?chb0kotlin
02/07/2018, 1:51 AMchb0kotlin
02/07/2018, 1:52 AMError:(26, 5) Kotlin: 'lateinit' modifier is allowed only on mutable properties
Error:(26, 5) Kotlin: 'lateinit' modifier is not allowed on properties with initializer
karelpeeters
02/07/2018, 2:05 AMclass Foo {
private lateinit var isChild:(File) -> Boolean
init {
isChild = { f -> roots.contains(f) || isChild(f.parentFile)}
}
}
should work, but it's not pretty.chb0kotlin
02/07/2018, 2:20 AMasad.awadia
02/07/2018, 2:24 AMchb0kotlin
02/07/2018, 4:05 AMcedric
02/07/2018, 7:45 AModay
02/07/2018, 8:04 AModay
02/07/2018, 8:04 AMdiesieben07
02/07/2018, 8:34 AMlet
unconditinoally on a String?
. let
is an extension function on Any?
.diesieben07
02/07/2018, 8:34 AMnull
, you need to use the safe-call operator ?.
.paccman
02/07/2018, 10:21 AMrun
standard function is better than let
. You are not using the value of x?.get(0)
whithin your block functiontulio
02/07/2018, 10:30 AMdiesieben07
02/07/2018, 10:31 AM@JvmStatic
on a field inside a class. Please clarify. And how are you trying to access it?tulio
02/07/2018, 10:35 AMtulio
02/07/2018, 10:36 AMtulio
02/07/2018, 10:36 AMtulio
02/07/2018, 10:37 AM'MY_STATIC_ARRAY' has private access in 'ClassA'
karelpeeters
02/07/2018, 10:37 AMcompanion
object if you want to make it static.diesieben07
02/07/2018, 10:38 AM@JvmField
, not @JvmStatic
.tulio
02/07/2018, 10:38 AMobject
already.diesieben07
02/07/2018, 10:38 AM@JvmStatic
only really makes sense in a companion object.tulio
02/07/2018, 10:38 AMtulio
02/07/2018, 10:39 AMtulio
02/07/2018, 10:39 AMtulio
02/07/2018, 10:40 AM