sksk
11/13/2018, 11:09 AMdata class CPosition(var x: Int, var y: Int)
fun main(args: Array<String>)
{
addComponent<CPosition>().apply {
x = 5
y = 5
}
}
fun <T : new> addComponent(): T
{
// create an instance of T
val c = T()
// do stuff with c
return c
}
marstran
11/13/2018, 11:15 AMfun <T> addComponent(createT: () -> T): T {
val c = createT()
// ...
return c
}
addComponent(::SomeClass)
sksk
11/13/2018, 11:16 AMkarelpeeters
11/13/2018, 11:20 AMaddComponent
.sksk
11/13/2018, 11:22 AMkarelpeeters
11/13/2018, 11:24 AMaddComponent<CPosition>()
vs addComponent(CPosition())
?sksk
11/13/2018, 11:27 AMorangy
karelpeeters
11/13/2018, 11:33 AMorangy
new
constraint doesn’t really help, because you’ll need to somehow return objects to the pool.aarjav
11/13/2018, 2:28 PMtschuchort
11/13/2018, 3:17 PMthemishkun
11/13/2018, 4:31 PMkarelpeeters
11/13/2018, 5:56 PMTimmy
11/14/2018, 3:39 PMDominaezzz
11/18/2018, 12:32 PMmemScope.allocArray<T>(block: T.() -> Unit)
. Although you'd have to do this for every "component".benleggiero
11/25/2018, 5:26 PMprotocol InitializablyWithZeroArguments
, which only requires that it has n initializer that takes zero arguments. Then I just use protocol `extension`s to make lots of mine and stdlib types conform to it.
Unfortunately, Kotlin seems to have no interest in making `interface`s specify a constructor. Nor does Kotlin seem to want late-declared conformance to be a thing. 😞