thhh
04/07/2021, 2:03 PMLynette Midy
04/07/2021, 2:39 PMDaniele B
04/07/2021, 4:45 PMupdate( B(firstField = objA.name, secondField = objB.surname) )
into something similar to this? (it doesn’t work)
update( ::objA )
given that the two classes have the same structure but just different property names?
so that I don’t need to manually specify each field?
val objA = A("John", "Walker")
fun update(obj : B) {
...
}
data class A (
val name : String
val surname : String
)
data class B (
val firstField : String
val secondField : String
)
N.B. I cannot modify the classes definition, by extending or implementing interfaceshisham bin awiad
04/08/2021, 10:02 AMCodewars
: and i found tow same ways with little diff so i need help :
how can know what is the beast code ? any tool to do that ? what easy way and good performance ?
Is the build time completed
when run app ,
can relies on it or nothhh
04/09/2021, 12:04 PMMark
04/10/2021, 4:44 AMthhh
04/10/2021, 3:11 PMit
is always not null."
The text in quotation was in response to:
What is actually the difference and what is the preferred to use:
Case 1:
variable?.let { //... }
Case 2:
if (variable != null) { //... }
thhh
04/12/2021, 1:55 PM"creating and linking nodes" example {
I don't understand how there's a string "creating and linking nodes"
then after a example
Please explain!
fun main() {
"creating and linking nodes" example {
val node1 = Node(value = 1)
node1.next = node3 // shortened for brevity
println(node1)
}
}
thhh
04/12/2021, 2:34 PMFilipe Duarte
04/12/2021, 6:36 PMtipsy
04/12/2021, 9:09 PMjava.lang.Object
in a map with type Map<Class<*>, Any>
, i'm getting the following error message that i'm not able to figure out:
Required type: capture of ? extends Object
Provided: Object
trofman
04/13/2021, 6:08 AMTravis Griggs
04/13/2021, 9:58 PMTheNewClass:TheParentClass {
var a:Foo
var b:Bar
var c:Baz
}
But primary constructors make it more interesting. Now I can declare them right in one line, which I don't mind when it's just that guy, something like:
data class Point<T>(val x:T, val y:T) { }
Now I've got to decode two types of object declarations when looking at them. But then I can mix and mash them:
class BLEConduit(val peripheral:BLEPeripheral):ConnectionConduit {
var sendBuffer = ubyteArrayOf()
var receiveBuffer:UByteArray? = null
So now I'm having to parse (and rationalize) two lists, to get at what the "guts" of an object is. And if I mix parameters without val/var in the primary constructor, any conciseness really breaks down. Are there a set of rules/guidelines others follow on when to put what where? To me, Kotlin's properties/init/constructors feels very evolutionary, like they started in one place, and then evolved things, but left backwards compatibility in place, and now there's less of a clear/idiomatic way to declare what an object is and how it gets initialized.tipsy
04/16/2021, 8:18 PMmyFunc(p1: String, p2: Consumer<*>, p3: String = "") {}
// is not the same as
myFunc(p1: String, p2: Consumer<*>) { myFunc(p1, p2, "") }
myFunc(p1: String, p2: Consumer<*>, p3: String) {}
the compiler does not allow you to use trailing lambdas if you use default arguments
i'm not really sure if it's an issue, but did seem odd to meushort
04/16/2021, 8:33 PMColton Idle
04/17/2021, 1:52 AM/**
* This class does this or that
*
but I always want to link to other classes or methods to help my team easily navigate to places that I reference, but I can never get it to work correctly. I also tried to search online for how to write common documentation like this, but I still can't get it to work. Apparently I just put a class name in brackets [] but when I pull up the documentation I can't click on it to navigate to that class. Does anyone know of like a nice crash course in documenting in kotlin code? Thank you!DMITRY.
04/19/2021, 1:29 PMabstract class Task<T : Enum<T>>(
@field:Id
@field:Indexed
open val id: ObjectId?,
open val group: Group
)
data class Change(
override val id: ObjectId?,
override val group: Group
) : Task<Status>(id, group)
enum class Group {
FIRST,
SECOND
}
-----
Ambiguous field mapping detected! Both private final ru.whatever.kek.tracker.model.Group ru.whatever.kek.tracker.model.task.Task.group and private final ru.whatever.kek.tracker.model.Group ru.whatever.kek.tracker.model.task.Change.group map to the same field name group! Disambiguate using @Field annotation!
but if I use @Field annotation I get this in MongoDB:Michael Böiers
04/19/2021, 4:39 PMfun parsedElements()
b) Define a function naming the data returned prefixed with get (since as per coding conventions functions should incorporate a verb): fun getParsedElements()
c) Define a read-only property naming the data returned: val parsedElements: List<String> get() = …
What’s considered best practice, does it depend on “how dynamic” the code is?Colton Idle
04/19/2021, 5:20 PMandym
04/22/2021, 3:07 PM!!
it.
But it seems I can’t use “this” in a contract:
contract {
returns(true) implies (this != null)
}
return !this.isNullOrBlank()
Is there a way to do this?Cath
04/23/2021, 11:00 AMvar byteArray = this::class.java.classLoader.getResource("abc.jpg").readBytes()
dave08
04/25/2021, 12:57 PM: Any
in generics to prevent nulls?interface UseCase<in Request : Any, out Response : Any> {
suspend fun execute(request: Request): Response
}
and in certain cases I need the Response to be nullable, and in others not. How can I implement such a Spy:
class UseCaseSpy<Request : Any, Response>(
private val returnIfNoResponse: (suspend (Request) -> Response)? = null,
private val allowNullResponse: Boolean = false
): UseCase<Request, Response> {
var request: Request? = null
var responseToReturn: Response? = null
override suspend fun execute(request: Request): Response {
this.request = request
val response = responseToReturn ?: returnIfNoResponse?.invoke(request)
if (response == null && !allowNullResponse)
error("Either responseToReturn or returnIfNoResponse needs to be provided.")
return response
}
}
execute
needs to return Response?
whether my actual type is nullable or not... so it just doesn't compileSomesh
04/26/2021, 4:39 PMstatus
, message
& data
keys will remain the same across the different API responses & only the content inside the data
JSON object will change, in this example, I have a JSON object with a member
key in other response I can have tournament
key.
{
"status": true,
"message": "Success",
"data": {
"member": {
"id": 21,
"emailAddress": "<mailto:abc@xyz.com|abc@xyz.com>",
"firstName": "ABC"
}
}
}
Currently, I am making use of generics and doing something like this
data class SignInResponse(
val `data`: Data<Member>
) : BaseResponse()
and BaseResponse
class has common JSON keys that I am getting, Here I'm using generics in data class passing the JSON class that is changing.
open class BaseResponse {
val status: Boolean = false
val message: String = UNDEFINED
}
@Keep
data class Data<T>(val actualData: T)
But this approach is incomplete because the above code will expect a JSON key actualData
but here JSON key can be a member
, tournament
, or anything. How can I pass the class in Data
class so that it can support the above JSON response?skwalking
04/27/2021, 8:07 AMTodoItemInlineEditor(
item = currentlyEditing,
onEditItemChange = onEditItemChange,
onEditDone = onEditDone,
onRemoveItem = { onRemoveItem(todo) }
)
In my case I wrote in this way:
TodoItemInlineEditor(
item = currentlyEditing,
onEditItemChange = {onEditItemChange}, ............................difference 1 writing inside {}
onEditDone = {onEditDone}, ............................difference 2 writing inside {}
onRemoveItem = { onRemoveItem(todo) }
)
by using onEditItemChange and onEditDone inside {} somehow made my app to stop working. So what is the difference by writing inside {} and without {} ?
onEditItemChange , onEditDone and onRemoveItem(todo) are lamda callback from:
@Composable
fun TodoScreen(
items: List<TodoItem>,
currentlyEditing: TodoItem?,
onAddItem: (TodoItem) -> Unit,
onRemoveItem: (TodoItem) -> Unit,
onStartEdit: (TodoItem) -> Unit,
onEditItemChange: (TodoItem) -> Unit,
onEditDone: () -> Unit
) {
.....
.....
TodoItemInlineEditor(
item = currentlyEditing,
onEditItemChange = onEditItemChange,
onEditDone = onEditDone,
onRemoveItem = { onRemoveItem(todo) }
)
....
....
}
John Pena
04/27/2021, 3:48 PMsynchronized
block, do i have to do anything special to call this function and ensure it completes?Slackbot
04/27/2021, 4:50 PMthhh
04/27/2021, 4:51 PMermac10k
04/28/2021, 9:35 AMJoe
04/29/2021, 5:11 PMreturn Builder.builder().withIntParam(intParam).let {
if (booleanFlag) {
it.withBoolean()
} else {
it
}
}.build()
anyone have a better pattern for something this? assuming the builder is mutable/side-effecty can change it to something like:
return ....apply {
if (booleanFlag) { withBoolean() }
}
which is a little cleaner but might not work with all builder impls?apahl
05/01/2021, 10:33 AMfun main() {
val (a, b) = Pair(1, "x")
}
Cannot access '<http://kotlin.io|kotlin.io>.Serializable' which is a supertype of 'kotlin.Pair'. Check your module classpath for missing or conflicting dependencies
I am using Kotlin 1.4.32 and Java 11.
Thanks a lot.apahl
05/01/2021, 10:33 AMfun main() {
val (a, b) = Pair(1, "x")
}
Cannot access '<http://kotlin.io|kotlin.io>.Serializable' which is a supertype of 'kotlin.Pair'. Check your module classpath for missing or conflicting dependencies
I am using Kotlin 1.4.32 and Java 11.
Thanks a lot.implementation("org.jetbrains.kotlin:kotlin-stdlib:1.4.32")
Doh.