Ben Edwards
08/11/2022, 3:48 PMBen Edwards
08/11/2022, 4:28 PMfun main() {
val min_sleep: Int = readln().toInt()
val max_sleep: Int = readln().toInt()
val hours_slept: Int = readln().toInt()
println(
if (hours_slept < min_sleep) {
"Deficiency"
} else if (hours_slept > max_sleep) {
"Excess"
} else {
"Normal"
}
)
}
Variable names should match the pattern: [a-z][A-Za-z0-9]*
What am I missing?juh juh
08/11/2022, 8:03 PMpoohbar
08/12/2022, 3:28 AMAnimal<Int>
fits into Animal<Any?>
. What am I missing?
open class Animal<T>
class Dog: Animal<Int>()
val x : Animal<Any?> = Dog() // error at the constructor call
Muhammad Talha
08/12/2022, 5:47 AM// A)
validate { credential ->
// ...
if (/* ... */) {
Some("thing")
} else {
null
}
}
// B)
validate { credential ->
// ...
if (/* ... */) {
return@validate Some("thing")
}
null
}
elye
08/12/2022, 8:36 AMenum class School(val zone: String, val captain: Student) {
Metricon("New York", Student.David),
Carlisle("London", Student.Paul)
}
enum class Student(val lastName: String, val school: School) {
David("Samuel", School.Metricon),
Solomon("Handsome", School.Metricon),
Saul("Black", School.Metricon),
Paul("Lewis", School.Carlisle),
Joseph("Hardy", School.Carlisle),
John("Baptise", School.Carlisle),
}
When I print it out
val student = Student.David
val school = School.Carlisle
println(student.school)
println(school.captain)
println(student.lastName)
println(school.zone)
It resulted in
Metricon
null
Samuel
London
Notice the null
there. The school.captain
is missing and became null.
How can I solve this problem?nbento.neves
08/12/2022, 9:17 AMkt
file with an object
inside an object
. I would like to know if someone can help me to understand the difference between using the object
and a companion object
. Is this the right way to use object
?
object Type {
object USER {
const val KEY = "key"
const val NAME = "name"
}
}
poohbar
08/12/2022, 3:17 PM::class
?
val c1 = Int::class.java to 42::class.java
c1.first to c1.second // (int, int)
val c2 = Int::class.java to 42
c2.first to c2.second::class.java // (int, class java.lang.Integer)
Ishan Iqbal
08/12/2022, 4:44 PMIshan Iqbal
08/12/2022, 4:44 PMIshan Iqbal
08/12/2022, 4:45 PMLandry Norris
08/12/2022, 4:49 PMBen Edwards
08/12/2022, 7:44 PM=
sign does not copy the object itself, it only copies a reference to it.". This only seems the case for immutable objects. if I made the variable a var this is not the case. This seems very important. I'm getting very disillusioned with the JetBrains Academy course. It's very slow going but still manages to seem to oversimplify things. Can anyone recommend a good beginners course with lots of excursuses? So far my favourite one is https://www.udemy.com/course/100-days-of-code/ (bit its a Python course). It covers a lot and the docent is not too bogged down with the fiddly, not very useful stuff. I really appreciate the effort they put in but I want something that is a bit more fun. I don't mind paying a bit.Abdullah Samir
08/13/2022, 12:40 AMBen Edwards
08/13/2022, 1:40 PModay
08/14/2022, 6:55 PMval names = ArrayListQueue<String>()
map["you"]?.forEach{
names.enqueue(it)
}
juh juh
08/14/2022, 9:04 PMRob Elliot
08/15/2022, 8:58 AMinterface Something {
String getAConstant();
}
and you want the value of getAConstant
to be a constant, is there a less verbose way than this?
class ConcreteSomething : Something {
private val _constant = "constant value"
override fun getAConstant(): String = _constant
}
(It's not actually a String, it's calculated by calling other methods on a supertype using a constructor value, just simplifying things.)Hassaan
08/15/2022, 9:39 AMsvenjacobs
08/15/2022, 12:59 PMclass Derived(
factory: (dep: Dependency) -> Base,
) : SomeBaseClass(), Base by delegate {
private val delegate = factory(dependency)
}
val SomeBaseClass.dependency: Dependency
get() = ...
juh juh
08/15/2022, 2:22 PMcommonMain
that I want to provide specific implementation on ONLY ONE multiplatform target, while using default common implementation for other, is there a way to do it without making class expect
and spamming actual
in every target?Jasmin Fajkic
08/15/2022, 4:29 PMpath.replace("/^\\/|\\/\$/g".toRegex(), "")
does not work.
2. what is easiest way to get search params as key value pair. /path/something?boom=true&id=bam. Want to have search params like boom:true , id: bam?sreich
08/15/2022, 5:49 PMpoohbar
08/15/2022, 7:36 PMif (obj instanceOf String myString) {
// myString
}
I know I can do as
and get a smart cast but I can’t give it a new name in Kotlin, right?sreich
08/15/2022, 8:03 PMclass CliOption2<T>(additionalProperties: MutableMap<String, Any>) {
val value by lazy {
val t = additionalProperties[cliOption.opt]!! as? T
t ?: throw NotImplementedError("cli option could not be casted")
t
}
how can i fix the cast warning here? I thought me throwing something if it fails would work. Why is it still considered unsafe and how can i fix this?Jerry Yion
08/16/2022, 2:44 AMNilotpal Saha
08/16/2022, 7:50 AMShervin
08/16/2022, 9:53 AMif
and when to use when
as the line between these two are very thin and we want to have an agreement in our team about their usage.Kenneth
08/16/2022, 10:45 AMM Saif Ullah
08/16/2022, 11:52 AMM Saif Ullah
08/16/2022, 11:52 AM