Triggered by this bug report AVRO-1814 I reduced the problem to this minimal example case in Java that simply shows the core of the effect.
package nl.basjes.experiment;
public class NamingClash {
String nl = "foo";
public void test() {
nl.basjes.experiment.NamingClash.foo();
}
private static void foo() {
// Do something
}
}
Trying to compile this will give you
error: cannot find symbol
nl.basjes.experiment.NamingClash.foo();
^
symbol: variable basjes
location: variable nl of type String
In AVRO the code is generated and it must try to avoid name collisions under the assumption people will sometimes choose unexpected names.
So assume in this example that
Other than telling people "Just don't do that".
Is there a solution to avoid these conflicts?
Note that for the AVRO bug that triggered this question I found a workaround. Here I'm looking for the 'generic answer'.
I can see two solutions to the problem:
1) call the method using a method name qualified only by just the current class name, instead of a fully qualified name:
public void option1() {
NamingClash.foo();
}
2) call the static method through the current class object's this
pointer, and suppress the "static-access" warning.
@SuppressWarnings("static-access")
public void option2() {
this.foo();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With