Since a static function call is translated into a static invocation bytecode regardless of how the definition exists… is there some way to force a caller of a static function to compile successfully even when the target function and class don’t exist yet?
I want to be able to compile calls to functions that don’t exist yet. I need to tell the compiler to trust me that at runtime, I’ll have them properly defined and in the classpath so go ahead and compile it for now.
Is there a way to do this?
Reflectively yes, but not via a regular call.
The call requires an entry in the string pool that includes the method name and parameter types so the compiler needs to be able to decide on a signature for the method.
Consider
Without knowing anything about
AClass, it could be a call to any ofAClass.aStaticMethod(int)AClass.aStaticMethod(int...)AClass.aStaticMethod(long)AClass.aStaticMethod(long...)floatanddoubleAClass.aStaticMethod(Integer)AClass.aStaticMethod(Number)AClass.aStaticMethod(Comparable<? extends Integer>)AClass.aStaticMethod(Object)AClass.aStaticMethod(Serializable)and probably a few others that I’ve missed.