Finally decided to add support for annotations for stack allocations, yay
This will solve compilation problems for JBullet users and make this library (JStackAlloc) more usable on it's own as the bytecode modification will be optional. My previous stance
about not recommending using it unless really necessary still applies though.
The old way will continue to work to anyone who wants it. After a bit of researching, the only option with annotations will be in this form:
@StackAlloc Vector3f vec = new Vector3f();
It will also allow to take any arguments (not just one of the same type like now), in that case the corresponding 'set' method will be used (similarly as in the old way). The ability to "directly" allocate output parameters, like this:
Vector3f avg = average(v1, v2, Stack.alloc(Vector3f.class));
isn't (currently) possible with annotations, so that won't be supported. In JBullet code base it will probably lead to slightly better utilization of such temporary objects as in some cases these temporary objects could be reused when allocating them explicitly through local variable declarations.
However, the bytecode modification is not sufficient to make this work as local variables annotations aren't exported to the bytecode. After a bit of researching, it seems it's doable by using annotation processor (which can be passed as an option to javac). There is no standard way to modify the classes, only by using compiler (javac) specific classes, like the Project Lombok