kevinherron
07/30/2021, 9:55 PMKotlin: Type of the constant expression cannot be resolved. Please make sure you have the required dependencies for unsigned types in the classpathwha?
zain
08/01/2021, 10:40 AMfunc getMode() -> Mode {
var mode: Mode = .live
switch (gdIsLocked, gdIsCurrent, matchIsLocked, matchIsCurrent) {
case (0,1,0,1):
mode = .manage
case (1,1,1,1):
mode = .live
case (1,1,1,0):
mode = .substitution
case (1,2,1,2):
mode = .points
case (0,0,0,0):
mode = .upcoming
default:
mode = .upcoming
}
return mode
}
enum Mode {
case manage
case substitution
case live
case points
case upcoming
}
Ayfri
08/02/2021, 2:50 AMTom Haywood
08/02/2021, 5:17 AMfun isXXX(current: Foo, previous: Foo?): Boolean {
val notTheSame = previous?.someField != someConstant
if (notTheSame) {
println("${previous?.someField} != $someConstant")
}
...
}
The data class:
data class Foo(
...
var someField: Short = initial,
...
)
The constants:
const val initial: Short = -1
const val someConstant: Short = 2
Could someone please help me understand the cause, or point me to where I should look? Code hasn't been touched for over a year, and I'm updating every single JAR used at the same time.
Thanks.Slackbot
08/02/2021, 2:18 PManatawa12
08/03/2021, 3:39 AMTwoClocks
08/03/2021, 5:25 PMInt
etc) copy on assignment, but classes create a reference on assignment. (see this simple example : https://pl.kotl.in/tTP-Co4SS). If I want to make my own numeric-ish type is there a way to behave the same as Int
on assignment?Alexis Manin
08/03/2021, 5:43 PMTwoClocks
08/03/2021, 11:21 PMif( thing != null && thing.value > 10)
I can't use thing?.value
because of a known bug in 1.5.20...Damien
08/03/2021, 11:43 PMout
parameter, but the compiler is complaining.
Error: Type parameter T is declared as 'out' but occurs in 'in' position in type (T) -> C<T>Matthew Cachia
08/04/2021, 9:14 AMinline fun <reified T> test(): Unit {
println(T::class.java.typeParameters.joinToString(separator = ","))
println(T::class)
}
fun main() {
test<Either<ReferenceObject, SchemaObject>>()
}
Is there a way I can retain ReferenceObject
, SchemaObject
? It looks like reified is not recursive...zain
08/04/2021, 4:16 PMTwoClocks
08/05/2021, 3:44 AMsumOf
on Iterable
for my own numeric-ish type. but I'm unsure on where to put it. If I put it in the file that calls sumeOf
it works, but if I put my impl in the file where my type is (which is where I think it should live), the compiler can't find it. Is there some magic to tell the compiler where the impl is?Mohammad Jahidul Islam
08/05/2021, 6:20 AMharis mehmood
08/05/2021, 10:43 AM{
"responseCode": 200,
"message": "Success",
"response": {
"Items": [
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f6"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f9"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f1"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f7"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f1511"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f1510"
},
{
"purpose": "Promotion",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"Version": "2012-10-17",
"amount": 500,
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f5"
},
{
"purpose": "Instant Checkup",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"amount": 1500,
"Version": "2012-10-17",
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f2"
},
{
"purpose": "Appointment fee",
"date": "16 Jul 2021",
"created_at": "Fri, 16 Jul 2021 09:54:10 +0000",
"uuid": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f3",
"Version": "2012-10-17",
"amount": 1000,
"Id": "4aa792da-2ef8-4253-8c7c-3e3f6b9f15f4"
}
],
"Count": 10,
"ScannedCount": 10,
"LastEvaluatedKey": "eyJJZCI6ICI0YWE3OTJkYS0yZWY4LTQyNTMtOGM3Yy0zZTNmNmI5ZjE1ZjQiLCAidXVpZCI6ICI0YWE3OTJkYS0yZWY4LTQyNTMtOGM3Yy0zZTNmNmI5ZjE1ZjMifQ=="
}
}
Can we use this kind of response For paging library 3 ?louiscad
08/05/2021, 10:57 AMSlackbot
08/05/2021, 2:09 PMJilles Soeters
08/05/2021, 7:18 PMList<String>
with about 250 URLs. Currently I am doing a GET
request to each url in a forEach loop so it’s synchronous. Obviously one of Kotlin’s amazing features is co-routines. Does anyone know of a good resource on how I could do this async? It’s currently taking 30 seconds while I feel like this could be done much much quicker async. Note I own all 250 URLs that are getting visited so I am not spamming anyoneFlorian
08/06/2021, 10:34 AM!!
operator?
Example: In an edit and delete situation I never expect the todoId
to be null, only when a new todo was added. Does it make sense to just use !!
then instead of the null-safe operator?
fun onAddEditResult(result: Int, todoId: Long? = null) {
viewModelScope.launch {
when (result) {
RESULT_TODO_ADDED -> eventChannel.send(Event.ShowTodoSavedConfirmationMessage("Todo added"))
RESULT_TODO_EDITED -> {
eventChannel.send(Event.ShowTodoSavedConfirmationMessage("Todo updated"))
setExpandedState(todoId!!, false)
}
RESULT_TODO_DELETED -> {
val todo = todoDao.getTodoById(todoId!!)
todo?.let {
todoDao.delete(todo)
setExpandedState(todo.id, false)
eventChannel.send(Event.ShowUndoDeleteTodoMessage(todo))
}
}
}
}
}
Scott Whitman
08/06/2021, 12:46 PMabstract class Length {
abstract val meters: Double
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Length) return false
return meters.equals(other.meters)
}
override fun hashCode() = meters.hashCode()
class Meter(value: Double) : Length() {
override val meters: Double = value
}
class Kilometer(value: Double) : Length() {
override val meters: Double = value * 1000.0
}
}
fun main() {
val oneKm = Length.Kilometer(1.0)
val oneThousandMeters = Length.Meter(1000.0)
println(oneKm.equals(oneThousandMeters))
// true
println(oneKm as Length == oneThousandMeters as Length)
// true
println(oneKm == oneThousandMeters)
// this will not compile: Operator '==' cannot be applied to 'Length.Kilometer' and 'Length.Meter'
}
Ayfri
08/06/2021, 3:57 PMMohammad Jahidul Islam
08/07/2021, 9:47 AMJasmine Dupré
08/07/2021, 9:12 PMSonu Sanjeev
08/08/2021, 4:07 AMvar isRectangle: Boolean
get() = field
set(value) = value.not() // The error is here
How is it possible to return a Unit type when we use a syntax like "set(value) = " . Thanks in AdavanceRafael Costa
08/08/2021, 10:16 AMAmountScreen
) be null?)althaf
08/08/2021, 5:39 PMfun make(rows: Int, cols: Int): String {
val table = StringBuilder()
for (rpos in 0..rows) {
table.append(START_ROW)
for (cpos in 0..cols) {
val cell = "${START_CELL}${cpos+rpos}${END_CELL}"
table.append(cell)
}
table.append(END_ROW)
}
return table.toString()
}
Robert Jaros
08/08/2021, 7:31 PMCannot access class '<http://java.io|java.io>.File'. Check your module classpath for missing or conflicting dependencies
or Cannot access class 'java.util.concurrent.Callable'. Check your module classpath for missing or conflicting dependencies
But there are no errors when building this project from Gradle command. Any ideas what can be wrong?smallufo
08/08/2021, 8:35 PMclass Config(var degree: Double = 315.0) {
init {
require(degree > 180 && degree < 360)
{ "degree should between 180 and 360" }
}
}
And if we initialize Config
directly , it will check the value as expected :
@Test
fun normalTest() {
try {
Config(90.0)
fail()
} catch (e: Exception) {
assertTrue(true)
}
}
But if there is a function accepting the Config
as functional object :
private fun calculate(block: Config.() -> Unit = {}) {
val cfg = Config().apply(block)
println("do something... with degree = ${cfg.degree}")
}
@Test
fun testCalculate() {
try {
calculate {
degree = 90.0
}
fail("It SHOULD fail")
} catch (e: Exception) {
assertTrue(true)
}
}
It will skip the init
check block .
How to solve this problem ? Thanks.
I could only think of this solution :
class Config(var degree: Double = 315.0) {
init {
check()
}
fun check() {
require(degree > 180 && degree < 360)
{ "degree should between 180 and 360" }
}
}
and …
private fun calculate(block: Config.() -> Unit = {}) {
val cfg = Config().apply(block).also { it.check() }
println("do something... with degree = ${cfg.degree}")
}
But I think it is so ugly … Is there any better way ? Thanks.andyg
08/08/2021, 11:15 PMMyApplication::class.java.`package`.implementationVersion
or
Thread.currentThread().contextClassLoader.getResources(JarFile.MANIFEST_NAME)
but they all result in a NULL. I looked deeper, IntelliJ doesn't even create a MANIFEST.MF when Running/Debugging (although it does when `gradle build`'ing a JAR file). Any tips on what I'm doing wrong? (this is NOT an Android project)y9san9
08/09/2021, 5:17 AM