elect
08/26/2019, 4:55 PMIntBuffer
, I'm writing an extension function for an Enum, where its companion object extends a specific interface. But if I cast, the compiler says the cast can never succeed.. why?
fun <E> Enum<E>.bind() where E : Enum<E>, E : A = (Enum.Companion as B).buffers[ordinal].bind() // this cast can never succeed
Sam Schilling
08/26/2019, 5:01 PMelect
08/26/2019, 5:01 PMEnum.Companion as B
Unit
jw
08/26/2019, 5:02 PMEnum
class, not the companion of the receiverSam Schilling
08/26/2019, 5:02 PMelect
08/26/2019, 5:03 PMRuckus
08/26/2019, 5:08 PMDominaezzz
08/26/2019, 5:16 PMEnum<E>
with an interface that can return it's "companion object". Won't be type safe but .... it works 😅.Ruckus
08/26/2019, 5:31 PMbind
to accept a B
elect
08/26/2019, 5:35 PMDominaezzz
08/26/2019, 5:36 PMelect
08/26/2019, 5:40 PMRuckus
08/26/2019, 5:43 PMDominaezzz
08/26/2019, 5:44 PMGlBufE
can have a method that returns an instance of GlBufEco
.elect
08/26/2019, 5:44 PMRuckus
08/26/2019, 5:49 PMfun <E> E.bind(...
instead of Enum<E>.bind(...
)Dominaezzz
08/26/2019, 6:09 PMT : Enum<T>
.Ruckus
08/26/2019, 6:14 PMbind
infinitely recursive?Dominaezzz
08/26/2019, 6:17 PMbind
.bind
just be a member at this point.elect
08/27/2019, 8:04 AMfun <T> T.bind(target: BufferTarget) where T : Enum<T>, T : GlBufE = T.buffers[ordinal].bind(target)
I get:
Error:(182, 70) Kotlin: Type parameter 'T' cannot have or inherit a companion object, so it cannot be on the left hand side of dot
fun <T> T.bind(target: BufferTarget) where T : Enum<T>, T : GlBufE = buffers[ordinal].bind(target)
Dominaezzz
08/27/2019, 8:13 AM