Ruckus
04/18/2018, 8:46 PMKarolo
04/18/2018, 10:56 PMzucen.co
04/19/2018, 9:31 AMwhen(string){
null -> ...
this.length>1 -> ...
else ->
}
i resorted to this:
when{
this==null -> ...
this.length>1 -> ...
else ->
}
is this idiomatic solution?Andreas Sinz
04/19/2018, 7:34 PMmap.getOrPut(key, { mutableSetOf() }).plusAssign(value)
thatadamedwards
04/19/2018, 7:38 PMotakusenpai
04/20/2018, 4:37 PMNico Smeenk
04/21/2018, 12:46 AMval objects = FXCollections.observableHashMap<KClass<A: BasicModel>, ObservableList<A: BasicModel>>()
inline fun <reified T: BasicModel> get(): ObservableList<T> {
return objects[T::class]
}
dave08
04/22/2018, 2:34 PMinvoke
operator to initialize an enum class
? I tried as an extension function, but the Intellij doesn't seem to see the constructor...Nirav Tukadiya
04/23/2018, 5:37 AMmarstran
04/24/2018, 12:51 PM(A.firstOrNull() ?: B.first()).field
. Or just split it into two lines: val first = A.firstOrNull() ?: B.first()
val field = first.field
Robert Menke
04/24/2018, 1:04 PMmorganbovi
04/24/2018, 4:56 PMvariable?.run{ }
== run this block if this thing is not null? correct?rellenberger
04/24/2018, 6:14 PMMathias Brandt
04/25/2018, 11:28 AMLong
return type. I am implementing the interface in a Java class, and I would like the return type to be Long
, but it says it has to be long
. How can I accomplish this? 🤔heyzoos
04/25/2018, 1:22 PMjavax.script
support that was introduced in Kotlin 1.1, however the first line always throws a NullPointerException
.
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
engine.eval("val x = 3")
println(engine.eval("x + 2")) // Prints out 5
I'm extremely new to this language and its tooling, is there something obvious I'm missing? I was under the impression that it would sort of just "come with" the language but I wouldn't be surprised at all if I need to install a dependency or two. My google skills have been failing me unfortunately.igorvd
04/25/2018, 2:39 PMclass C {
private val _elementList = mutableListOf<Element>()
val elementList: List<Element>
get() = _elementList
}
ebonet
04/26/2018, 1:02 PM0rph3u
04/26/2018, 6:55 PMNztom
04/26/2018, 10:58 PMwilyarti
04/28/2018, 2:14 PMohwelp
04/28/2018, 7:58 PMcrazdrms
04/30/2018, 2:23 AMobj
is automatically cast to String
on the right-hand side of &&
if (obj is String && obj.length > 0) {
return obj.length
}
return null
}
Why is it Int here?marlin
05/01/2018, 1:58 PMMathias Brandt
05/01/2018, 2:41 PMtextChangedListener
to multiple input fields. Currently I have this:
withdraw_input.textChangedListener {
afterTextChanged {
validateInput()
}
}
reg_number.textChangedListener {
afterTextChanged {
validateInput()
}
}
I cannot figure out how to extract the listener to a variable and then re-use it, instead of defining the same listener multiple times.
I guess it’s just a syntax issue 🤔 Any hints? 🙂bjonnh
05/01/2018, 6:25 PMJamie Huson
05/01/2018, 8:16 PMif(isNull(someString)) { someString.length } else { someString.length }
, the first someString.length
would give an error or somethingkarelpeeters
05/01/2018, 9:57 PMexpect
.karelpeeters
05/02/2018, 12:22 AMleosan
05/02/2018, 11:55 AM#SWIFT
enum NumberCategory {
case Small
case Medium
case Big
case Huge
init(number n: Int) {
if n < 10000 { self = .Small }
else if n < 1000000 { self = .Medium }
else if n < 100000000 { self = .Big }
else { self = .Huge }
}
}
How I can achieve something like this in kotlin?
Just to illustrate my problem I have a bunch of business logic conditionals that I want to convert to a type and send it to my view, I’m not even sure if this is the best solution or I stick with boolean methodskarelpeeters
05/02/2018, 11:57 AMfromNumber
or something like that.