0

メソッドが継承を認識しない理由が見つかりません。ここで何が欠けていますか?

public class Rate extends BaseResource
public class GenericQuote extends BaseResource
public class Payment extends GenericQuote

public void handleMediationErrors(BaseResource response)

handleMediationErrors(myRate) <-- 動作する
handleMediationErrors(myPayment) <-- コンパイル時に失敗すると、想定してBaseResourceいないことがわかりますPayment

4

1 に答える 1

2

There's nothing wrong with the example you've given - perhaps you're using a different BaseResource in one of the classes (importing a different one or declaring it separately elsewhere - this can cause confusion!)

To prove it, this example compiles perfectly:

class BaseResource {}
class Rate extends BaseResource {}
class GenericQuote extends BaseResource {}
class Payment extends GenericQuote {}

public class Test {

    public void handleMediationErrors(BaseResource response) {}

    public static void main(String[] args) {
        new Test().handleMediationErrors(new Payment());
        new Test().handleMediationErrors(new Rate());
        new Test().handleMediationErrors(new GenericQuote());
        new Test().handleMediationErrors(new Payment());
    }
}
于 2012-09-19T13:54:45.003 に答える