Mustafa
10/16/2019, 7:40 AMSteph Carter
10/16/2019, 3:13 PMEmil Orvik Kollstrøm
10/16/2019, 8:26 PMpoohbar
10/16/2019, 9:57 PMExtensions.kt
in the same package but in two different modules. Maven compiles everything successfully but when running it it suddenly can't find some of the extension methods. Is that a bug?poohbar
10/16/2019, 10:28 PMjava.lang.NoSuchMethodError
. Pretty odd that it fails at runtime.Steve Young
10/17/2019, 3:20 AMkushalp
10/17/2019, 1:05 PMKafkaAvroDeserializer
? I'm getting the following error:
Unsupported Avro type. Supported types are null, Boolean, Integer, Long, Float, Double, String, byte[] and IndexedRecord
https://github.com/sksamuel/avro4kAshutosh Panda
10/17/2019, 3:53 PMvar numbers=arrayOf(
11,
12,
13,
14,
15
)
var integer:MutableList<Int>=mutableListof()
for(x in 0 until (numbers.size-1)) {
integer[x]=numbers[x]
}
for(element in integer) println("$element")
Sam Schilling
10/17/2019, 5:25 PMelaborate tissue
10/17/2019, 6:43 PMMichael
10/17/2019, 6:52 PM.processor { it }
where processor can take a Function
or a Functional Interface.Marc Knaup
10/18/2019, 10:44 AMDeprecationLevel.HIDDEN
and use it anyway? 🙂Paul Dhaliwal
10/18/2019, 8:49 PMsealed class Result<out T : Any?> {
data class Success<out T : Any>(val data: T) : Result<T>()
data class Unauthorized(val exception: Exception) : Result<Nothing>()
data class Timeout(val exception: Exception) : Result<Nothing>()
data class Error(val exception: Exception) : Result<Nothing>()
}
and I’d like to make a mapping extension function like so Result<EntityModel>.toDomain(DomainModel) which would output Result<DomainModel>.
So if the object was Success<UserEntityModel> it would return Success<UserDomainModel>jmfayard
10/19/2019, 8:54 AMJoan Colmenero
10/19/2019, 3:42 PMsealed class
?
sealed class ResultWrapper<T> {
data class Success<T>(val data: T) : ResultWrapper<T>()
data class Unauthorized(val exception: UnauthorizedException) : ResultWrapper<Nothing>()
data class Forbidden(val exception: ForbiddenException) : ResultWrapper<Nothing>()
data class Network(val exception: NetworkException) : ResultWrapper<Nothing>()
data class NotFound(val exception: NotFoundException) : ResultWrapper<Nothing>()
data class BadRequest(val exception: BadRequestException) : ResultWrapper<Nothing>()
data class Error(val exception: Exception) : ResultWrapper<Nothing>()
}
Then I have a method that returns a ResultWrapper<T>
but I'm only able to return the ResultWrapper.Success(it)
how can I return the other ones?Ashutosh Panda
10/20/2019, 9:52 AMimport kotlin.arrayOf as arrayOf1
var i=0
var number:Array<Int> = arrayOf(11,12,13,14,15)
var integer: MutableList<Int> = mutableListOf(5) {0}
for(x in 0 until 5) {
integer[x]=number[x]
}
println(integer[2])
This is program and the error is -error: none of the following functions can be called with the arguments supplied:
@SinceKotlin @InlineOnly public inline fun <T> mutableListOf(): MutableList<Int> defined in kotlin.collections
public fun <T> mutableListOf(vararg elements: Int): MutableList<Int> defined in kotlin.collections
var integer: MutableList<Int> = mutableListOf(5) {0}-
Ashutosh Panda
10/20/2019, 9:57 AMimport kotlin.arrayOf as arrayOf1
var i=0
var number:Array<Int> = arrayOf(11,12,13,14,15)
var integer: MutableList<Int>(5) {0}
for(x in 0 until 5) {
integer[x]=number[x]
}
println(integer[2])
this is the changed one and error is `
error: property getter or setter expected
var integer: MutableList<Int>(5) {0}`
John
10/20/2019, 7:10 PMArkadii Ivanov
10/20/2019, 8:32 PMException: factory functions used to create instances of classes can have the same name as the class being createdBut what is the recommended style?
Sergio C.
10/20/2019, 8:49 PMobject Extensions {
inline fun <reified T : Any> SharedPreferences.getObject(key: String): T? {
return Gson().fromJson<T>(getString(key, null), T::class.java)
}
}
can't call mySharedPrefs.getObject<Object>(KEY)Joan Colmenero
10/21/2019, 7:23 AMGyuhyeon
10/21/2019, 8:44 AMif (someObj != null) {
val someOtherLogic = repository.selectOne(someObj.field)
someOtherLogic.doThis()
someOtherLogic.doThat()
} else {
someService.someBusinessLogic()
}
apparently, checking null with if
statements is not the "kotlin way". someObj?.also {
val someOtherLogic = repository.selectOne(someObj.field)
someOtherLogic.doThis()
someOtherLogic.doThat()
} ?: run {
someService.someBusinessLogic()
}
but honestly, this looks like some serious code-smell to me. Maybe it's because I come from java, but if what the code is trying to achieve is do some business logic based on the isExists state of an object and do something else if it doesn't exist
, using ?.also{} ?: run{}
seems way worse than an explicit easy to read if / else
.
Any input would be appreciated.Georgi Naumov
10/21/2019, 11:32 AMMartin Jinoch
10/21/2019, 11:33 AMDaan
10/21/2019, 3:47 PMHarry
10/21/2019, 9:50 PMbodiam
10/22/2019, 12:18 AMMemberTbl.select {
MemberTbl.member_id eq "200"
}.first().also {
assertThat(it[MemberTbl.id]).isEqualTo("200")
}
But, I'd like to refactor it to something like: MemberTbl.findByMemberId("200")
with the help of an extension function, since this code is duplicated quite a lot.
What I have so far is this:
private fun MemberTbl.findByMemberId(s: String, row: ResultRow.() -> Unit) = this.select { member_id eq s }.first().also { row (it) }
So that my end result will look like this:
MemberTbl.findByMemberId("200") {
assertThat(it[MemberTbl.id]).isEqualTo("200")
}
But that won't, since the it
in the assertEquals is no longer the closure passed in. How can I fix this?PabloCasia
10/22/2019, 6:06 AMinfix fun Any.fun1(block: () -> Unit) = block.invoke()
infix fun Any.fun2(block: () -> Unit) = block.invoke()
And I'm trying to use variables from first fun on second fun, something like:
fun1 { val item1 = "" } fun2 { val item2 = item1 }
But item1 scope is only fun1
Any suggestions? Aware from declare as a lateinit var outside the functionsPaul Woitaschek
10/22/2019, 7:36 AMgavvvr
10/22/2019, 11:23 AMgavvvr
10/22/2019, 11:23 AMwasyl
10/22/2019, 11:26 AMgavvvr
10/22/2019, 2:39 PMMike
10/22/2019, 2:59 PM