Scott Christopher
09/10/2020, 1:43 AMType mismatch. Required: P, Found: <P>
error for the returned value.
interface A
interface B
interface C
fun <P> resolve(): P where P : A, P : B, P : C {
return object : A, B, C {}
}
Is there some variation of this that is possible?streetsofboston
09/10/2020, 1:48 AMinterface A
interface B
interface C
interface P : A, B, C
fun resolve(): P {
return object : P {}
}
Scott Christopher
09/10/2020, 1:49 AMScott Christopher
09/10/2020, 1:49 AMinline fun <reified P> resolve(): P where P : A, P : B, P : C {
return object : A, B, C {} as P
}
This seems to not complainScott Christopher
09/10/2020, 1:49 AMstreetsofboston
09/10/2020, 1:50 AMas P
is what makes it work, I think.Scott Christopher
09/10/2020, 1:53 AM<reified P>
streetsofboston
09/10/2020, 1:55 AMstreetsofboston
09/10/2020, 1:56 AMP : A, B, F
is not the same as Q : A, B, C
, where Q
is the object
in your code.Scott Christopher
09/10/2020, 1:57 AMScott Christopher
09/10/2020, 1:58 AMRuckus
09/10/2020, 1:59 AMP
, so you can't guarantee you're returned object will match what they expect.streetsofboston
09/10/2020, 2:01 AMP
may expect a method that your returned object
does not provide.Scott Christopher
09/10/2020, 2:24 AMScott Christopher
09/10/2020, 4:10 AMinline
/`reified` properties, so we're back to utilising a (likely simpler) solution with data classes instead. Thanks for your help though.Kroppeb
09/10/2020, 9:18 AMScott Christopher
09/10/2020, 9:32 AMKroppeb
09/10/2020, 9:44 AMScott Christopher
09/10/2020, 9:50 AMScott Christopher
09/10/2020, 9:51 AMstreetsofboston
09/10/2020, 11:28 AMas P
is an unsafe type cast?Scott Christopher
09/10/2020, 11:29 AM