https://kotlinlang.org logo
m

Muneebshere

08/08/2019, 10:49 AM
d

Dominaezzz

08/08/2019, 10:52 AM
I read somewhere (can't find it now), there is a vague-ish plan for this feature, but there are a lot of questions to answer, like which class loader does the generated class belong to and other stuff. I'll post a link when I find it.
s

simon.vergauwen

08/08/2019, 10:53 AM
I've walked around this in the passed using an interface and a reified constructor function. But might depend on the use case if that'll work for you or not.
d

Dominaezzz

08/08/2019, 10:55 AM
s

simon.vergauwen

08/08/2019, 10:57 AM
Example of how to walk around it using
interface
&
reified fun
.
r

Ruckus

08/08/2019, 1:41 PM
@Muneebshere Please follow the channel topic:
All discussion in this channel should begin with a use-case or proposal instead of a question.
m

Muneebshere

08/09/2019, 12:45 PM
@Ruckus I've phrased it as a question, but it is a proposal (the linked post is mine). I wanted to get feedback both here and there, so instead of copying over the whole post, I just put up a link to the forum thread. This way, people here who are interested enough to click on the link will be able to read not only the content, but also the discussion on the forum.
And I really recommend that the discussion be read, because already (as of two commentators), the idea's becoming a bit more crystallized by prompting me to think of things I hadn't thought of before.
@simon.vergauwen Yes,
inline reified
constructor functions are very useful sometimes, but the methods of the generic class still don't have access to the type parameter. For that you'd have to inline the whole class.
@Dominaezzz Please do. Would be most welcome.
s

simon.vergauwen

08/09/2019, 12:52 PM
In the example I gave I use it the
reified A
in a method?
m

Muneebshere

08/09/2019, 12:58 PM
@simon.vergauwen Oh, I'm sorry, I didn't catch that before. Yes, you're right. In fact I'm using this very approach right now in what I'm working on (details in the forum thread comments). But you're actually manually inlining the type. My question is (and I know this is a very selfish question to ask), can't the compiler do that? For my example I had to do this inlining for about a hundred classes (don't ask😓) which are all implementations of a generic base class, all with different `T`s.
s

simon.vergauwen

08/09/2019, 1:02 PM
Ouch 😕 Yes, that’s indeed required. I don’t think it’s a selfish thing to ask, I have needed this from time to time when inter-opting with Java libs.
👍 1
m

Muneebshere

08/09/2019, 2:26 PM
@simon.vergauwen I actually used regular expressions to generate all those inline implementations, so wasn't too hard. But looking at and maintaining 3000+ lines of code which consists of the same repetition is the hard thing.
4 Views