https://kotlinlang.org logo
#announcements
Title
# announcements
p

pavlospt

03/17/2017, 2:31 PM
And what I want is to just call that method on something like:
Copy code
override fun <T> getFoo() : T? { return fromBytes(byteArray) }
o

okkero

03/17/2017, 2:46 PM
In this case, you would need a reifiable reference to T
p

pavlospt

03/17/2017, 2:47 PM
True, but I cannot have one, right?
o

okkero

03/17/2017, 2:47 PM
Maybe you could pass a
KClass<T>
though the constructor of the enclosing class?
p

pavlospt

03/17/2017, 2:49 PM
Hmm I am not following 😕
o

okkero

03/17/2017, 2:54 PM
getFoo is in a class, right?
p

pavlospt

03/17/2017, 3:05 PM
yeap
o

okkero

03/17/2017, 3:43 PM
then the common Java way of doing it has been to add an extra parameter to the constructor
hm
hold on, I just realised T is not part of the class, but of the function
p

pavlospt

03/17/2017, 3:48 PM
Hehe that’s what is been killing me for some hours now 😞
Unfortunately I ended up providing the Class<T> through the method..
2 Views