Home > Mobile >  Return proper object from comparison
Return proper object from comparison

Time:07-14

I have the following code:

public class FeeContext {
}
public class DefaultContext {
}

Code:

private FeeContext generateDefaultOrTierContext(FeeDto fee) {
    FeeContext ctx = createDefault(fee);
    return ctx == null ? createTierContext(fee) : ctx;
  }

  private DefaultContext createDefault(FeeDto fee) {
    DefaultContext defaultContext = new DefaultContext();
    ....
    return defaultContext;
  }

  private TierContext createTierContext(FeeDto fee) {
    TierContext tierContext = new TierContext();
    .....
    return tierContext;
  }

I get error:

Required type: FeeContext
Provided: TierContext

I suppose that TierContext should extend FeeContext but I;m not sure is this correct. I tried this but again I get the same issue. Do you know how this can be solved? The code block should be correct.

CodePudding user response:

TierContext and DefaultContext have to extend FeeContext:

public class TierContext extends FeeContext {}
public class DefaultContext extends FeeContext {}
  •  Tags:  
  • java
  • Related