Big Chungus
11/26/2019, 12:39 PMNew111
11/26/2019, 11:24 PMColton Idle
11/27/2019, 4:54 AMif (myItem != null) { //do something }
makes sense in kotlin as it does in java. Is using let{}
really needed? Would someone say that my if statement is not idiomatic? I like to follow the 90 day rule. If I come back to the code in 90 days... which one will I understand? I feel that most would choose the if.KtNewbie
11/27/2019, 7:15 AMobadz
11/27/2019, 10:37 AMjk2018
11/27/2019, 11:33 PMchervak.av
11/28/2019, 7:51 PMchervak.av
11/29/2019, 6:55 PMvar regWord = word.toRegex
var list = line.split(Regex("""^(regWord)+"""))
i need to count regWord in lineKy Leggiero
12/01/2019, 3:48 AMArslan Mushtaq
12/01/2019, 7:19 PMHoanghun5
12/01/2019, 10:23 PMHullaballoonatic
12/01/2019, 10:26 PMiterface Foo : Comparable<Bar> {
override fun equals(other: Any?) = when (other) {
is Comparable<*> -> // other is Comparable<Bar> && (other as Comparable<Bar>).compareTo(this) == 0
else -> false
}
}
cast as and try/catch?Steve
12/01/2019, 11:53 PMSlackbot
12/02/2019, 5:50 AMmike_shysh
12/02/2019, 1:57 PMobject DBProvider {
@Volatile private var dbSession: Session? = null
fun getDBSession(): Session = dbSession ?: synchronized(this) {
dbSession ?: when (dbType) {
DBTypes.MYSQL.type -> MySqlSession(host = dbHost, port = dbPort).getSession()
DBTypes.ORACLE.type -> OracleSession(host = dbHost, port = dbPort).getSession()
else -> throw Exception("Unsupported DB type - $dbType.")
}.also { dbSession = it }
}
...
antoniomarin
12/02/2019, 4:30 PMset
or distinct
lists from a list of objects based on their property? Currently I’m looping through each user and adding them one by one to the set
val userEmails = mutableSetOf<String>()
users.forEach {
userEmails.add("Adding unique email: ${it.email}")
}
print(userEmails)
Damian
12/02/2019, 6:21 PMpackage aquarium
class Aquarium (var length: Int, var width: Int, var height: Int) {
var volume: Int
get() = width * height * length / 1000
set(value) = {height = (value * 1000) / (width * length)}
This is the warning I'm getting from Intellij for the set(value):
Type mismatch: inferred type is () -> Unit but Unit was expected
I don't understand what is this supposed to signify?Steve
12/02/2019, 8:20 PMbbaldino
12/02/2019, 8:57 PMClass<T Extends Enum<T>>
out of it. for example:
fun <T : Any>test(valueType: KClass<T>) {
when (valueType) {
Enum::class -> {
// How to get 'x' to be Class<T> where T extends Enum<T> ?
val x = valueType.java
}
else -> TODO()
}
}
Oleh Ponomarenko
12/03/2019, 8:21 AMval chunks = data.asIterable().chunked(CHUNK_SIZE)
For example, I need an index (from original array) of first byte in second chunk.Ruyi Li
12/03/2019, 1:26 PM> kotlinc -script .\p2.kts
error: invalid argument: -script
info: use -help for more information
Anyone know why this is happening? I'm on Windows and installed Kotlinc through the zip on the releases page, and when I run kotlinc -version
it outputs
> kotlinc -version
info: kotlinc-native 1.3.60 (JRE 9.0.1+11)
Kotlin/Native: 1.3.60
-script is not listed in the options specified in -help.victor-mntl
12/04/2019, 12:51 AMfun myFunction (foo :MyClass) { /.../ }
and call it like:
val foo = MyClass( /.../ )
foo.myFunction()
Oya Canli
12/05/2019, 1:26 PMmyBoolean ^= true
So if it was true, it becomes false and if it was false it becomes true. Is there an equivalent in kotlin?df
12/05/2019, 5:13 PMval catalogues = mapOf(
"de-catalogue" to listOf(29L, 10010L, 10012L, 10013L),
"fr-catalogue" to listOf(10007L, 10019L, 10020L),
"nl-catalogue" to listOf(10008L, 10023L, 10024L),
"it-catalogue" to listOf(10021L),
"es-catalogue" to listOf(10022L)
into a Map<Long,String> where each list value becomes the key and the key (from the original map) becomes the valueHarsh Mistry
12/05/2019, 6:10 PMbbaldino
12/05/2019, 7:14 PMinternal
, but when i include that lib (via a maven dependency) in a java project, i can still access that constructor. am i misunderstanding the scope of internal
?Ellen Spertus
12/05/2019, 11:49 PMresults
as long as the list neededPermissions
where every element of results
has the value PackageManager.PERMISSION_GRANTED
except for a single element. Here’s my code:
val results = neededPermissions.map { PackageManager.PERMISSION_GRANTED }.toIntArray()
results[0] = PackageManager.PERMISSION_DENIED
I know how to do what I want in Scheme (with cons
and cdr
). What’s a nice way to do it in Kotlin?Ive Vasiljevic
12/06/2019, 8:54 AMclass User(private val map: MutableMap<String, String>) {
val name: String by map
val lastName: String by map
}
class User1(private val map: MutableMap<String, String>) {
val name: String
val lastName: String
init {
name = map["name"].toString()
lastName = map["lastName"].toString()
}
}
So basically, when accessing property "name" from class User in the fun main(). It is using MutableMaps default getValue() implementation to get the value?Oleh Ponomarenko
12/06/2019, 2:23 PMval bytes = fileOut.readBytes().sliceArray(range)
And then I send the bytes. I do nothing with this after. As I understand JVM garbage collector should clean this data myself after a while but does it not always.
I google this, I think I can use something like try-with-resources in Java - use
. But this extension is unable for the Class.
Do you have some advice for me? Thanks.Florian
12/07/2019, 9:05 AMFlorian
12/07/2019, 9:05 AMMilan Hruban
12/07/2019, 9:26 AMFlorian
12/07/2019, 12:15 PMthis
keyword to access the property?Mike
12/07/2019, 1:11 PMFlorian
12/07/2019, 4:09 PMMike
12/07/2019, 4:27 PMinit
block is the constructor. So, in that case, you'd have to use this
and it would refer to the property, name, and not the 'constructor parameter' name.Florian
12/07/2019, 5:14 PMtoUpperCase
callMike
12/08/2019, 1:46 PM