mfulton26
02/14/2017, 9:56 PMvar port = -1
wouldn't suffice (it would be cheaper than a delegate property).artem_zin
02/14/2017, 10:08 PMlateinit
uses null
as “not-initialized”, at the same time Int
will be interpreted as primitive java int
whenever possible to avoid allocation on heap, that means that combination of any primitive types with lateinit
is not possible because lateinit
needs reference type (for null
) but primitives are not reference types… We’re facing it from time to time and have to fallback to Delegates.notNull()
as suggested before, you can vote for IDE quickfix for that https://youtrack.jetbrains.com/issue/KT-12515artem_zin
02/14/2017, 10:10 PMBut I wonder whyBecausewouldn't suffice (it would be cheaper than a delegate property).var port = -1
-1
can be valid initialized value for your business logic.sreich
02/14/2017, 10:12 PMartem_zin
02/14/2017, 10:15 PM-1
will be used as “not-initialized” state by lateinit
internally, surely you can use some default value if possible, but beauty of lateinit
is that it removes if (initialized)
checks from your codesreich
02/14/2017, 10:16 PMaimozg
02/14/2017, 10:18 PMport
could be "non-initialized", why not make it Int?
sreich
02/14/2017, 10:25 PMsdeleuze
02/14/2017, 10:27 PM@LocalServerPort var port: Int? = null
is probably the right solutionaimozg
02/14/2017, 10:27 PMlateinit
is "could be non-initialized but I want to work with it as if it was always initialized with background checks if necessary"sdeleuze
02/14/2017, 10:27 PMaimozg
02/14/2017, 10:27 PMsdeleuze
02/14/2017, 10:28 PMInt?
mfulton26
02/14/2017, 10:28 PMlateinit
for boxed-primitives via generics but simply doesn't have the grammar to directly express it.aimozg
02/14/2017, 10:29 PM@NotNull Integer
and int
Paul Woitaschek
02/14/2017, 10:50 PMRob
02/14/2017, 11:56 PMsreich
02/15/2017, 12:05 AMpoohbar
02/15/2017, 2:45 AMsquare
to the Math
standard Java classpoohbar
02/15/2017, 2:45 AMfun Math.square(a: Double) = Math.pow(a, 2.0)
poohbar
02/15/2017, 2:45 AMpniederw
02/15/2017, 2:53 AMpoohbar
02/15/2017, 3:09 AMpoohbar
02/15/2017, 3:10 AMval myLambda = { (x, y), z ->
println(x,y,z)
}
pniederw
02/15/2017, 3:50 AMpniederw
02/15/2017, 3:53 AMval myLambda: (Pair<Int, Int>, String) -> Unit = { (x, y), z ->
println(x)
println(y)
println(z)
}
mg6maciej
02/15/2017, 9:33 AMBiFunction(::aFunc)
where BiFunction
is SAM, interface is Java
and aFunc
is just a top-level function.kirillrakhman
02/15/2017, 9:36 AMkirillrakhman
02/15/2017, 9:36 AMBiFunction
is a SAM, a synthetic constructor that takes a lambda is generated.mg6maciej
02/15/2017, 9:37 AMBiFunction { a, b -> aFunc(a, b) }
.