domfox
10/20/2017, 1:55 PMpublic <T> T[] toArray(Foo<T> foo, Class<T> tClass) {
return (T[]) foo.getListOfT().stream().toArray(size -> (T[]) Array.newInstance(tClass, size));
}
kingsley
10/20/2017, 2:06 PM//Callable from Kotlin
inline fun <reified T: Any> doStuff() = doStuff(T::class.java)
// Callable from java
fun <T: Any> doStuff(clas: Class<T>) = Unit
karelpeeters
10/20/2017, 2:07 PMkingsley
10/20/2017, 2:08 PMT
in the non-reified one would be erased, so it won’t be possible to call reified with T from non-reifieddomfox
10/20/2017, 2:09 PMdomfox
10/20/2017, 2:11 PMtoTypedArray()
on a List<T>
, and I suppose I could instead construct a suitable array using my Class<T>
and populate it manually...kingsley
10/20/2017, 2:15 PMtoTypedArray
itself is reified, and since it’s impossible to go from non-reified to reified in this case. I guess you’d have to fall back to some sort of unsafe castingkarelpeeters
10/20/2017, 2:16 PMreified
requires the function to be inline
so it's probably more complicated than that.domfox
10/20/2017, 2:20 PMClass<T>
doesn't in general carry enough type information to do all the work that a reified type parameter could do. A reified type parameter basically picks up the type declared to the compiler in the code into which the function is inlined, including any of its type parameters. That information is lost - erased - if all you have in hand is List.class
, for example.domfox
10/20/2017, 2:21 PMkingsley
10/20/2017, 2:22 PMkiku
10/20/2017, 4:56 PMkiku
10/20/2017, 4:56 PMkiku
10/20/2017, 4:57 PMkiku
10/20/2017, 4:57 PMlynas
10/20/2017, 5:21 PMkevinmost
10/20/2017, 5:25 PMprivate
and don't use it anywhere else in the fileevanchooly
10/20/2017, 5:35 PMevanchooly
10/20/2017, 5:41 PMorangy
nkiesel
10/20/2017, 10:10 PMclass C : A by AImpl() , B by BImpl()
but that would not handle renaming of properties. And also falls apart if AImpl() and BImpl() require complex parameters (e.g. Bimpl
needs value from AImpl
), or if AImpl() and BImpl() each provide half the required properties from the base interfacekristofdho
10/20/2017, 11:54 PMpsycoderblog
10/21/2017, 12:19 AMDaniel Illescas
10/21/2017, 1:42 PMkarelpeeters
10/21/2017, 1:42 PMDaniel Illescas
10/21/2017, 1:42 PMorangy
Daniel Illescas
10/21/2017, 1:55 PM