projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.92k stars 2.39k forks source link

Primitive Pseudo Generics #3252

Open Angular-Angel opened 2 years ago

Angular-Angel commented 2 years ago

Describe the feature A kind of pseudo generic for primitive classes. So, one can write a Vec3 class, and then use this notation to make variants of it for bytes, shorts, ints, longs, floats, doubles, etc. As opposed to simply writing Vec3b, Vec3s, Vec3i, Vec3l, Vec3f, and Vec3d. Same principle can be applied to other Vecs, Matrices, and any other class you might wan to write a copy of for several different primitives.

Describe the target audience People doing math, physics, and graphics, mainly - but I'm sure lots of other programmers will be able to find a use for it.

Additional context This would be far superior to simply coping a class and doing "find, replace: Primitive 1 -> Primitive2", which is the current easiest method.

Angular-Angel commented 2 years ago

Oh, for bonus points, find a way to allow specifying vecs of arbitrary length? This one is probably too specific and an absolutely unreasonable pain to write, but, it'd be neat to be able to demand a Vec42l with the same ease one gets a Vec3i.

janrieke commented 2 years ago

This sounds to me more like a use case for a regular annotation processor, because you are generating new classes. Lombok focuses on modifying existing classes.

Angular-Angel commented 2 years ago

Not entirely true! @Builder creates new classes, I'm pretty sure. So, there is precedent.

janrieke commented 2 years ago

Of course you could do it with lombok and generate all of those as inner classes.

But I don't think you want that, for several reasons:

This will take years. For example, @SuperBuilder took more than 4 years until it reliably worked with all IDEs.

If you want such a feature, write your own annotation processor. It's significantly easier than adding it to Lombok, and it will work with common IDEs out of the box.