Daniele B
08/13/2020, 9:18 PMdata class State (
val aField : String
val bField : String
val cField : String
)
I would like to wrap this copy function:
wrapperobject.state = wrapperobject.state.copy (aField = aValue, bField = bValue)
inside a custom method like this:
wrapperobject.changeState(aField = aValue, bField = bValue)
what would be the code for it?
I am not sure how to define the argument of the changeState
methodColton Idle
08/14/2020, 5:31 AMisNotNullOrEmpty
doesn't exist by default?
I hate having to do !something.isNullOrEmpty
Colton Idle
08/14/2020, 6:58 AMwhen (it) {
is EventDriver.Stop -> ...
is EventDriver.Go -> ...
}
and
when (it) {
EventDriver.Stop -> ...
EventDriver.Go -> ...
}
seem to compile and run fine. What's the difference? I would have expected is
to be required here?Joshlemer
08/15/2020, 1:26 PMMartin KvL
08/15/2020, 4:42 PMDaniele B
08/15/2020, 9:07 PMmyList
.sortedBy { val calculatedField = it.fieldA / it.fieldB }
.mapIndexed { index, elem -> MyNewObject(
_index = index+2,
_value = calculatedField,
_fieldA = fieldA.toInt()
_fieldB= fieldB.toInt()
)
}
unfortunately this code doesn’t work: I can’t access calculatedField from inside the map functionblue
08/15/2020, 11:16 PM==
and equals
same in Kotlin? If so, can someone help me why my program is returning false
for below inputs
John 19 0
John 19 22
import java.util.*
data class Client(val name: String, val age: Int, val balance: Int) {
fun equals(other: Client?): Boolean {
return this.age == other?.age && this.name == other.name
}
}
fun main(args: Array<String>) {
val input = Scanner(System.`in`)
val n = input.next()
val a = input.nextInt()
val b = input.nextInt()
val nn = input.next()
val aa = input.nextInt()
val bb = input.nextInt()
println(Client(n, a, b) == (Client(nn, aa, bb)))
}
huehnerlady
08/17/2020, 11:20 AMdata class Test(val property1: String?, property2: Int?)
and I would like to check if that property1 and property2 are not null. But I would like this generic for any object, not this specific one.
I currently check, if the String of the object does not contain null, BUT this feels a bit hacky.
Any idea how I can do that better?Colton Idle
08/17/2020, 7:36 PMstatic Function1<MyManager, String> doTheManaging(){
return MyManager::condense;
}
The kotlin converter can't seem to convert this. Can anyone point me in the right direction?
Converter gives me a new companion object
then
fun doTheManaging(): Function1<MyManager, String> {
return { valueMap: Map<String, Any> -> condense(valueMap)}
}
but the entire return statement is redMark
08/19/2020, 4:59 AMemptyList()
for example:
val retrievedList = myMap[someKey] ?: emptyList()
now gives a compiler warning (though the IDE doesn’t complain) when trying to access items in retrievedList
so I need to explicitly set List<MyListItemType>
as the retrievedList
type or the emptyList()
generic. I can’t seem to reproduce this in the kotlin playground, so can only assume there is some inconsistency caused by my gradle build scripts or some build caching issue.Eugene Freeman
08/19/2020, 7:09 AMCarrascado
08/19/2020, 6:01 PMursus
08/20/2020, 9:49 PMpages.toMutableMap().apply { this[currentPage] = it }.toMap())
Divelix
08/21/2020, 7:03 AMBen Butterworth
08/21/2020, 9:55 PMscope.launch{}
, what do you call those curly braces? I know the last parameter type seems to have to be a lambda, often called block
Will Nixon
08/23/2020, 11:57 PMKevin
08/24/2020, 6:53 AM<LinearLayout
android:id="@+id/linear_main"
xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:tools="<http://schemas.android.com/tools>"
xmlns:app="<http://schemas.android.com/apk/res-auto>"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World"
android:textColor="@color/Black01"
/>
/*insert some kind of tag in here to call the id of new_image element from second_file.xml*/
</LinearLayout>
second_file.xml
<LinearLayout
android:id="@+id/linear_second"
xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:tools="<http://schemas.android.com/tools>"
xmlns:app="<http://schemas.android.com/apk/res-auto>"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/new_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/button_image"
/>
</LinearLayout>
Will Nixon
08/24/2020, 12:46 PMcsturtevant
08/24/2020, 8:40 PMimport io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class ViewControllerTest {
private val repository: TaskRepository = mockk()
private lateinit var viewController : ViewController
@BeforeEach
fun setUp() {
viewController = ViewController(repository)
every { repository.findTasksFromView(any()) } returns emptyList()
}
@Test
fun getView() {
val list = viewController.getView(1)
println(list)
}
}
The regular unit test is here:
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
import kotlin.test.assertEquals
internal class TaskTest {
private val project: Project = Project(1, "Inbox","The default project", emptyList())
@BeforeEach
fun setUp() {
}
@Test
fun `maps Task to Viewable using extension function`() {
val task : Task = buildTask()
val viewable : Viewable = task.toViewable()
assertViewable(viewable)
}
private fun buildTask() : Task {
return Task(
1,
"Get focused",
"TODO",
project
)
}
private fun assertViewable(viewable: Viewable) {
assertAll(
{assertEquals(1, viewable.id)},
{assertEquals("Get focused", viewable.name)},
{assertEquals("TODO", viewable.status)},
{assertEquals(project, viewable.project)},
)
}
}
Someone else is having the same issue on StackOverflow: https://stackoverflow.com/questions/62208145/why-is-mocking-so-slow-to-start-in-kotlingjesse
08/25/2020, 2:08 PMby
keyword). the interface is defined in java and has some default
methods. my class does not override those methods. i was expecting them to be forwarded to the delegate, but instead the default version is used. do i have to explicitly override all default
methods in order to forward them to the delegate?Kenneth
08/26/2020, 9:49 AMOleh Ponomarenko
08/26/2020, 10:34 AMSaul Wiggin
08/26/2020, 1:26 PMKenneth
08/26/2020, 2:49 PModay
08/26/2020, 4:46 PMhttps://i.imgur.com/g0mrTBN.jpg▾
zero_coding
08/26/2020, 7:23 PMclass NoInterestsFound : RuntimeException()
zero_coding
08/26/2020, 8:39 PMdata class Connector(val url: String, val username: String, val pw: String) {
fun connect(): Database = Database.connect(url, "com.impossibl.postgres.jdbc.PGDriver", username, pw)
}
oday
08/27/2020, 8:27 AM.toString()
not print its contents and only print the type?Will Nixon
08/27/2020, 3:32 PMzero_coding
08/27/2020, 7:26 PMzero_coding
08/27/2020, 7:26 PMMatteo Mirk
08/28/2020, 8:17 AMEnvironmentVariables()
and you should be able to retrieve them using the square bracket notation config[...]
, that’s it.