basher
02/10/2019, 5:37 PMCzar
02/10/2019, 5:41 PMbasher
02/10/2019, 5:52 PMnfrankel
02/10/2019, 6:56 PMbasher
02/10/2019, 7:06 PMlouiscad
02/10/2019, 7:18 PMnfrankel
02/10/2019, 7:49 PMbasher
02/10/2019, 7:55 PMgildor
02/11/2019, 5:15 AMtypeOf
operator?basher
02/12/2019, 12:26 AMtypeOf
actually. i'm looking to be able to call a constructor on a generic type that's constrained to inherit from an abstract class that requires that constructorgildor
02/12/2019, 12:33 AMbasher
02/12/2019, 5:53 PMwouldn't be more clear and flexible solution provide factory for the type?Being frank: coming from another language where it's common to have static requirements on generic abstract types and interfaces, factories feel like a crutch. You instantiate them once, so that you can use their instance methods like static methods
gildor
02/13/2019, 12:49 AMbasher
02/13/2019, 4:58 PMAlso, how can you instantiate interface?
fun <T: SomeInterface> makeOne(): T {
return T()
}
If interfaces allowed static requirements, like constructors, you could do something like that ^gildor
02/13/2019, 5:10 PMinline fun <reified T: SomeInterface> makeOne(): T {
return T::class.java.newInstance()
}
basher
02/13/2019, 5:13 PMconstructor
defs in `interface`sgildor
02/13/2019, 5:14 PMbasher
02/13/2019, 5:15 PMgildor
02/13/2019, 5:15 PMbasher
02/13/2019, 5:17 PMfun <T: SomeInterface> makeOne(): T {
return T()
}
gildor
02/13/2019, 5:18 PMbasher
02/13/2019, 5:19 PMgildor
02/13/2019, 5:20 PMfun <T : SomeInterface> makeOne(factory: () -> T): T {
return factory()
}
basher
02/13/2019, 5:24 PMgildor
02/13/2019, 5:24 PMbasher
02/13/2019, 5:27 PMAlso reified generics without constructor doesn't give you compile type safetyI don't know enough about Kotlin/Java to refute that yet. Swift is able to do this with compile-time safety though somehow, but they're different languages with different constraints. 🤷♂️
gildor
02/13/2019, 5:29 PMbasher
02/13/2019, 5:29 PMgildor
02/13/2019, 5:30 PMbasher
02/13/2019, 5:32 PMgildor
02/13/2019, 5:33 PMbasher
02/13/2019, 5:34 PMgildor
02/13/2019, 5:35 PMbasher
02/13/2019, 5:35 PMgildor
02/13/2019, 5:37 PMbasher
02/13/2019, 5:37 PMgildor
02/13/2019, 5:39 PMbasher
02/13/2019, 5:43 PMgildor
02/13/2019, 5:44 PMbasher
02/13/2019, 5:47 PMgildor
02/13/2019, 5:56 PMCzar
02/13/2019, 5:57 PMbasher
02/13/2019, 5:59 PMgildor
02/13/2019, 5:59 PMCzar
02/13/2019, 6:04 PMbasher
02/13/2019, 6:06 PM