How can you deprioritize a constructor overload? I...
# getting-started
h
How can you deprioritize a constructor overload? I added the new optional constructor:
Copy code
@JvmInline
value class AsyncValue<T>(private inline val getter: suspend () -> T) {
  constructor(queryResult: suspend () -> AsyncValue<T>) : this (getter = {
        queryResult().getter()
  })
}
With this code, the current usage of
AsyncValue { //myCode }
needs to return
AsyncValue
and not
T
. Workaround is to use change all old code from
AsyncValue { }
to
AsyncValue(getter = { })
.
y
I haven't tried this, but instead of using constructors, have 2 different methods named
AsyncValue
and annotate the
T
one with
@OverloadResolutionByLambdaReturnType
Also, I'm very surprised that
inline val
is a thing for value classes. Do you have any more info about that? Does it actually inline the lambda or something? I can't quite tell what's happening there
1
h
Yeah, using a helper function would a valid workaround.
Honestly, I have no information about inlining the variable too. Guess it needs a class code or bytecode analysis if this modifier has any effect