They do if the method you're calling is compiled. But this wouldn't necessarily require bytecode revision e.g., an annotation could preserve the names.
Right. But naming arguments is necessary only for methods with one or more default parameters. If 118 could be altered to silently target those methods, sure.
It's a different story FYI. Annotation arguments are backed by methods, which support defaults and are exported from the very beginning, but normal parameters lack a lot of these infrastructure.
But I suppose introducing named parameters for carrier classes / records could be a good starting point as they already have some of these.
If you could recompile the world then sure, but since this would have to work without recompilation[1] - I'm not so sure anymore.
Let's say we have an application that has a Dependency A. Dependency A calls a method in Dependency B using named parameters. With this de-sugaring by the compiler (or compiler callsite magic, as it was called before), the DepA would work fine as long as DepB was exactly in the version DepA was compiled against.
Now, since the programmer used named parameters, what would happen if a newer version of DepB swapped argument order around? The programmer referred to an argument by name, so it would be a reasonable expectation that the platform would somehow do the right thing here.
Without support from the JVM, if this feature was just compiler[1] smoke & mirrors then either:
a MethodNotFoundException would be thrown if signature changed, or
ParamA would suddenly have a value meant for ParamB if the types accidentally matched and the signature did not change (think SomeType method(int paramA, int paramB)), or
the compiler would have to inject a hefty amount of bytecode at the callsite to get the parameters via reflection and then figure out the right invocation, costing a bunch of CPU cycles.
Frankly, it would be a disaster. On the other hand the support from JVM would probably be pretty expensive to implement, especially with projects like Parametric JVM on the horizon. I kinda see why the team at Oracle is prioritizing other features.
I'm pretty sure that Kotlin just throws a NoSuchMethod and expects library developers to use traditional overloading if they don't want to break binary compatibility.
Yes, it would be a reasonable assumption. But many things are reasonable assumptions until you know better.
Since it's susceptible to the exact same issue with parameter reordering as is not using parameter but gives you benefits while writing code, I don't really think this is a big deal.
Why can we have default values and named parameters in annotations then? Are we not worried about the same things there? Does the vm explicitly support them?
> Now, since the programmer used named parameters, what would happen if a newer version of DepB swapped argument order around? The programmer referred to an argument by name, so it would be a reasonable expectation that the platform would somehow do the right thing here.
Usually, named arguments are optional, so it can't be reasonable expectation. There are not giving runtime safety, just like Generics. Your assumption might be correct in some structured typed world (javascript) where name becomes key in some dynamic structures.
View all comments
Show parent comment
5
u/javaprof Jan 22 '26
Yes, basically named arguments can be de-sugared into regular call by the compiler.
Supporting default arguments would be tricky tho