Ifvwm
05/21/2020, 5:48 AMMananpoddarm
05/22/2020, 8:05 AMMark
05/23/2020, 1:34 AMJoshua
05/23/2020, 11:57 AMJP
05/23/2020, 6:30 PMany
and `all`: do they short-circuit, or do they evaluate the predicates for the whole items?bitnot
05/23/2020, 7:49 PMval (_) = Unpackable("Two")
does not call component1
?Mark
05/24/2020, 3:37 AMoperator fun invoke(...): MyClass?
to return a nullable value, or is that confusing to the caller since it looks like a constructor call?Mark
05/24/2020, 6:28 AM{{A}, {B, C}, {D, E}}
to {{A, B, D}, {A, C, D}, {A, B, E}, {A, C, E}}
?Ali
05/27/2020, 6:14 PMJP
05/28/2020, 6:50 AMhashCode()
and toString()
implementation for the cases where I don’t define a class as data class?
For example when I examined with a class like this:
class ListNode(var elem: Int) {
var next: ListNode? = null
}
fun main() {
val node = ListNode(123)
println(node.hashCode()) // 895328852
println(node.toString()) // ListNode@355da254
node.elem = 456
println(node.hashCode()) // 895328852
println(node.toString()) // ListNode@355da254
}
whereas when I examined when changing to data class:
data class ListNode(var elem: Int) {
var next: ListNode? = null
}
fun main() {
val node = ListNode(123)
println(node.hashCode()) // 123
println(node.toString()) // ListNode(elem=123)
node.elem = 456
println(node.hashCode()) // 456
println(node.toString()) // ListNode(elem=456)
}
From this my assumption is that the hashCode()
and toString()
depends on the memory address when the class is not a data class, whereas in case of data class, it will not depend on the memory address but the properties which are defined in the primary constructor (which makes sense, since that would be what data classes are for and how they should behave).
Is my assumption correct?
And where can I see these default implementations for hashCode()
, both for class and data class? I wasn’t able to find them.Slackbot
05/29/2020, 10:25 AMClaudiuB
05/29/2020, 7:19 PMval
-ness, a sort of lazy by
? Confused of the heuristics here. Should I make it var
if I plan on it changing? adapter
doesn't change, the onActionPerformed
can
val onActionPerformed: ((String, Any) -> Unit)?
get() {
return adapter?.onActionPerformed
}
Mark
06/01/2020, 2:41 AMif (text.length < 40) {
// left pad with zeros
text = String(CharArray(40 - text.length)).replace('\u0000', '0') + text
}
text = text.padStart(40, '0')
oday
06/01/2020, 9:59 AMRishav Sharan
06/01/2020, 6:49 PMinit
name has a strikethroughoday
06/03/2020, 12:31 PMit.items
with a new object whose toggled
variable is now changed?
it.items.map { item ->
item.copy(toggled = createSearchParams?.condition?.contains(item.itemValue)!!)
}
oday
06/03/2020, 12:32 PMitem.itemValue
is equal to createSearchParams?.condition? and set the toggled status of that item to trueEvan R.
06/03/2020, 12:44 PM.map()
creates a copy of the original listoday
06/03/2020, 6:52 PM?:
?Ryan
06/04/2020, 11:55 AMVampire
06/05/2020, 9:07 AMenum class Boo(private val fooDelegate: String? = null) {
BAZ,
BAM(fooDelegate = "bar");
val foo: String
get() = fooDelegate ?: error("no foo set for ${javaClass.simpleName}.${name}")
}
I want that if foo
is needed, it must have been set, but if it is not used, it is not necessary to set it.
Optimally I like to access it by name foo
and also set it by name foo
instead of setting it by name fooDelegate
or optionalFoo
.
When getting foo
, I want it to be of type String
though, not String?
.waltermcq
06/05/2020, 3:05 PMwaltermcq
06/05/2020, 3:06 PMVampire
06/05/2020, 6:38 PMopen class A
interface B
class AB: A(), B
class CD: A(), B
fun <T> foo(t: T): Nothing? where T : A, T : B = null
val a = foo(AB())
val b = listOf(AB()).map(::foo)
val c = listOf(AB(), CD()).map(::foo)
The last one with c
is not compiling.
Does anyone have an idea how to make the last line also work?
It gives the compilation error
Type parameter bound for T in fun <T : A> foo(t: T): Nothing? where T : B is not satisfied: inferred type Any is not a subtype of ASo it seems while the created list could be of needed types
A
and B
, the type inference is not smart enough here but creates a List<Any>
Is there a way to fix this, e. g. to explicitly define the List type somehow?
Interestingly the type inference in IntelliJ is smart enough to handle it properly and does not show an error, only the compiler bails out.Sudhir Singh Khanger
06/06/2020, 11:14 AMv79
06/06/2020, 2:58 PMunion
type - I know it's not coming. Can anyone think of a less verbose way of implementing these combination of sealed classes?
val modifiers: MutableMap<String,Attribute> = mutableMapOf()
sealed class Attribute {
data class fValue(val value: Float) : Attribute() {
override fun toString(): String {
return value.toString()
}
}
data class iValue(val value: Int): Attribute() {
override fun toString(): String {
return value.toString()
}
}
data class sValue(val value: String): Attribute() {
override fun toString(): String {
return value.toString()
}
}
data class bValue(val value: Boolean): Attribute() {
override fun toString(): String {
return value.toString()
}
}
data class lValue(val value: Long) : Attribute() {
override fun toString(): String {
return value.toString()
}
}
}
oday
06/08/2020, 7:22 AMDominick
06/09/2020, 5:33 AMWesley Acheson
06/09/2020, 1:00 PMpublic class TotallyMadeUpClass{
private String username
public String getUsername(){ return this.username }
public void setUsername(String username) {
if (username.length > 10)
throw new IllegalArgumentException()
this.username = username}
}
Bruce McLaren
06/10/2020, 4:11 PMBruce McLaren
06/10/2020, 4:11 PMShawn
06/10/2020, 4:15 PM