Вопрос

I'm facing the following error-message by Eclipse:

The method getString(String, BasicNameValuePair[]) is ambiguous for the type Class1

for the following code:

public final class Class1 {
    public static void getString(String requiredArguments, BasicNameValuePair[] dataPairs) {

    }

    protected static void getString(String requiredArguments, byte[] dataBytes) {

    }
}

public final class Class2 {
    public static void callTest() {
        Class1.getString("This is a test", null);
    }
}

The code in callTest() will result in the error above.

It's clear that null can be converted to BasicNameValuePair[] aswell as to byte[], but note the protected modifier here. The method with byte[] as argument shouldn't be visible to Class2 at all and thus not be ambiguous.

Why is the protected method visible to other (not subclassed) classes and causing this error?

Это было полезно?

Решение

Because these classes are on the same package?

The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top