hallvard
10/30/2019, 3:07 PMdata class
and builder pattern exist, or is it even possible? I'd like the simplicity of a data class, but with setters that return this
... Anyone?Travis Griggs
10/30/2019, 6:31 PMsomeByte == 13u
. Is it possible to implement an unbalanced equals override that will let me compare these without having to put toUByte() or toUInt() in everywhere. I tried something like:
fun UInt.equals(b:UByte) : Boolean {
return this == b.toUInt()
}
(and the reverse as well)
But == sites still complainmagisu
10/30/2019, 10:32 PMmagisu
10/30/2019, 10:32 PMxenoterracide
10/31/2019, 7:06 AMvar
(from java 10)?James
10/31/2019, 9:15 AMAnimesh Sahu
10/31/2019, 10:21 AMgianluz
10/31/2019, 10:24 AMBikram
10/31/2019, 11:07 AMJérôme Gully
10/31/2019, 12:35 PMjeggy
10/31/2019, 1:19 PMYan Pujante
10/31/2019, 2:37 PMMartin Nordholts
10/31/2019, 3:19 PMval map: Map<String, Int>? = mutableMapOf("one" to 3)
map?.["one"] // <- Why is this not allowed?
map?.get("one") // <- Which is equivalent to this, which works
Hullaballoonatic
10/31/2019, 6:21 PMelse ""
, else 0
, etc?:
return myStr + if (myCondition) myPostfix else ""
return myVal + if (myCondition) myAddition else 0
obviously the nicest syntax would probably simple exclude the else
, but that of course does not compilepavel
10/31/2019, 9:29 PMList<Pair<A,B?>>
Is there an easy way to filter out all where second==null
and make the type be List<Pair<A,B>>
?alwyn
10/31/2019, 9:53 PMval t = '\u223C' // TILDE
val a = "A" + t + "B" + t + "C"
val b = "A~B~C"
val c = "A${t}B${t}C"
println (a == b) // false
println (b == c) // true
?Alex Kuznetsov
10/31/2019, 10:20 PMAnastasia Finogenova
11/01/2019, 2:42 AMVishnu Haridas
11/01/2019, 2:08 PMwhen
expression that returns different types:
fun main(){
val x = readLine()?.toInt() ?: 0
val y = when(x){
1 -> 42
2 -> "Hello"
else -> 3.14F
}
println(y::class.java)
}
During runtime (Kotlin 1.3.41 on JVM 1.8) this is the output:
When x
= 1, it prints class java.lang.Integer
When x
= 2, it prints class java.lang.String
Otherwise, it prints class java.lang.Float
When does the compiler determine the type of y
? Or, how does the compiler infers the type of y
during compile-time?
Question on StackOverflow: https://stackoverflow.com/q/58479824/816416Shane Blackburn
11/01/2019, 5:06 PMToddobryan
11/02/2019, 2:03 AMAny?
instead of Number?
fun String.toNumber(): Number? = toIntOrNull() ?: toLongOrNull() ?: toBigIntegerOrNull()
jimn
11/02/2019, 1:50 PMRobinVdB
11/02/2019, 5:07 PMHullaballoonatic
11/02/2019, 7:37 PMfun <N: Int | Byte> foo(n : N) = n.toDouble() / 4.5
TypeScript has them, so I'd imagine JB would want to have it for Kotlin/JS.Hullaballoonatic
11/02/2019, 8:34 PMfizz
returned nullable, then foo.fizz()?.log()
John
11/03/2019, 5:26 PMwithIf(myObject.propertyToFiler == true) { myObject -> ... }
Cody Moore
11/03/2019, 9:25 PMVishnu Haridas
11/04/2019, 10:05 AMval
with a backing property, or a public property with a private setter? Is there any difference?
For example,
class Foo {
// (1) - public property with a private setter
var isSyncing = false
private set
// (2) - val with a backing property
private var isSyncing_ = false
val isSyncing get() = isSyncing_
}
Melvin Biamont
11/04/2019, 2:00 PMinline functions
.
How can I make an inline function stopping/returning the calling function?
Basically, I would like this :
//This method should return the calling function
inline fun onUserNull() = run {
Timber.e("User is null")
return
}
fun fetchUserIdentity() {
val currentUser = userDataSource.currentUser ?: onUserNull()
presenter.displayUserIdentity(currentUser)
}
Would do the same as:
fun fetchUserIdentity() {
val currentUser = userDataSource.currentUser ?: run {
Timber.e("User is null")
return
}
presenter.displayUserIdentity(currentUser)
}
pavi2410
11/04/2019, 6:28 PM::
be overloaded?