Lulu
11/18/2020, 8:47 PMMutableList
, and I expose it to another function with just the List
interface, can that function cast it to MutableList
? At what point is something cast-able to its original type? I'm not new to generics but I haven't thought about that before.igor.wojda
11/19/2020, 8:51 AM// Kotlin class
data class Test(
val name: String,
val lastName :String?
)
// Generated Java class src
public final data class Test public constructor(name: kotlin.String, lastName: kotlin.String) {
}
Since this class will be also used from Java is there any way to include Nullable
and NonNull
annotations in generated the code for the properties? Something like this:
// Generated Java class src
public final data class Test public constructor(@NonNull name: kotlin.String, @Nullable lastName: kotlin.String) {
}
(I mostly care about NonNull
):
The main drive for this behaviours is that now I can create new instance of Test
class from Java and pass null values new Test(null, null)
without any indication that this is wrong/undesired usage- I believe with annotations IDE would display error/waring 🤔Bernhard
11/19/2020, 9:39 AMfloor(int1.toDouble() / int2).toInt()
mzgreen
11/19/2020, 11:41 AMelizarov
11/19/2020, 12:45 PMdewildte
11/19/2020, 5:03 PMDispatchQue
?
I have a MutableMap<T,T>
and I want to make operations done to it thread safe.
So far I just wrap accesses to it in:
val lock = Any()
synchronised(lock) { map.doTheThing() }
Is this fine?Ncrnomarkovic
11/19/2020, 5:08 PMStavFX
11/19/2020, 5:51 PMfoo
is not being smart casted to non-null even tho it cannot be null in that else block.
Shouldn’t the compiler be smart enough to infer this?
class Foo(val str: String? = "")
val foo: Foo? = null
if (foo?.str.isNullOrBlank()) {
//...
} else {
println(foo.str) // doesn't compile. foo is not smart-casted to a non-null type
}
Btw if the condition was foo?.str == null
, this would compile. so it’s not impossible to “backtrack” from str
to foo
in this casedimsuz
11/20/2020, 12:18 AMval property: String?
in src/main
and then in src/test
I have if (property != null) property.length
and this gives an error that property
cannot be smart-casted, because it's defined in a different module. But it's the same [gradle] module!
Also I have just moved this class + its test from another module where there was no such error. Why can this happen? Drives me nuts. Tried to compile outside an IDE from console, same errors...ursus
11/20/2020, 5:00 AMAuthenticator
class which has login()
function
Now, app B needs logout as well, so it extends Authenticator and adds logout()
functionality.
How would you call such type?
1) If I were to take inspiration from the way List interface looks I'd call it LogoutableAuthenticator
But such name looks silly for app B developers, as they only use a Authenticator
which has both login and logout functions
1.5) Give it app name prefix like AppBAuthenticator
. Also feels silly. All app B types then should have this prefix
2) Or, design it backwards, leave leaf implementations prefixless, so app B has Authenticator but it extends BaseAuthenticator
. But this again looks stupid in shared code
3) Name them both Authenticator and let just the package name be differentAnimesh Sahu
11/20/2020, 5:48 AMAnimesh Sahu
11/20/2020, 8:04 AMRaid Xu
11/20/2020, 8:39 AMGlobalScope
in a singleton class?Ben Hammond
11/20/2020, 12:04 PMFixedThreadPool
executor within a synchronized block, and I pass in a ThreadFactory Lambda fun;
when the threadfactory function is subsequently evaluated, will the Monitor lock be acquired?
(I am hoping/expecting not - otherwise I would put the sychronized inside the ThreadFactory fn)mattinger
11/20/2020, 7:17 PMPratik Tandel
11/20/2020, 8:19 PMakuleshov7
11/20/2020, 11:34 PMColton Idle
11/21/2020, 3:05 AMliminal
11/21/2020, 3:08 AM.with(key: String, value: String)
, .with(key: String, value: Boolean)
. i'd like to be able to call these functions conditionally on the call site. i can't think of anything better than simply adding a param .with(key: String, value: String, shouldUse: Boolean)
to determine if a value should be used internally by the builder if shouldUse
is trueAnimesh Sahu
11/21/2020, 10:16 AMTolriq
11/21/2020, 3:47 PMNikky
11/22/2020, 3:11 AMval filteredMap: Map<String, B> = someMap.filterValues { value -> value is B } as Map<String, B>
because the unchecked cast is marked as warningfrank
11/22/2020, 6:36 AMAlexander Karkossa
11/23/2020, 1:00 AMhoang
11/23/2020, 10:57 AMkotlin 1.4.20
and Optional<V>
Type mismatch: inferred type is Optional<V!!> but Optional<V> was expected
the same code compile ok in kotlin 1.4.10
fun first(vPredicate: (V) -> Boolean): Optional<V> {
val v: V? = firstOrNull(vPredicate)
return if (v == null) {
Optional.empty()
} else {
Optional.of(v)
}
}
the errored line is the one that return Optional.empty()
user
11/23/2020, 11:33 AMBernhard
11/23/2020, 11:39 AMfun XMLStreamWriter.writeStuff(action: XMLStreamWriter.() -> Unit)
how does Kotlin know where it takes the this from?Slackbot
11/23/2020, 1:52 PMAlexander Black
11/23/2020, 5:13 PMNcrnomarkovic
11/23/2020, 5:48 PMNcrnomarkovic
11/23/2020, 5:48 PMhoang
11/23/2020, 5:52 PMfun Merchant.loc() = this.latitude to this.longitude
sorry if there’s any syntax error, I just type it outnanodeath
11/23/2020, 5:59 PMval loc get() = latitude to longitude
Ncrnomarkovic
11/23/2020, 6:04 PMnanodeath
11/23/2020, 6:07 PM