This is basically to cut my teeth for much more ambitious code generation down the line, but I think it could be performance and useful.
the new syntax is:
There are some differences between this version and Dmitriy's implementation:
- it is no longer necessary to declare whether the method is static or not. This is gleaned via reflection.
- as per the above, it is no longer necessary to make the first argument be the type of the object to invoke the method on. If it is not a static method, then the type will implicitly be the type you need. So in the case of concat, it would need to be passed a tuple of two inputs: one for the method to be called against (as it is not static), and then the 'string' that was specified. In the case of valueOf, because it IS static, then the 'String' is the only value.
- The arguments are type sensitive. Integer means the Object Integer, whereas int (or long, or float, or boolean, etc) refer to the primitive. This is necessary to properly reflect the arguments. Values passed in WILL, however, be properly unboxed as necessary.
- The return type will be reflected.
This uses the ASM API to generate the bytecode, and then a custom classloader to load it in. I will add caching of the generated code based on the input strings, etc, but I wanted to get eyes and opinions on this. I also need to benchmark, but it should be native speed (excluding a little startup time to make the bytecode, but ASM is really fast).
Another nice benefit is that this bypasses the need for the JDK, though it adds a dependency on ASM (which is a super tiny dependency).
|Status||Resolved [ 5 ]||Closed [ 6 ]|
|Status||Patch Available [ 10002 ]||Resolved [ 5 ]|
|Resolution||Fixed [ 1 ]|
|Status||Open [ 1 ]||Patch Available [ 10002 ]|
|Fix Version/s||0.12 [ 12323380 ]|
|Fix Version/s||0.11 [ 12318878 ]|
|Fix Version/s||0.10.1 [ 12320547 ]|
|Field||Original Value||New Value|