Search code examples
javainheritanceinner-classesquickfixj

Why would I not be able to access a method from an extended nested class?


I'm attempting to access a method inside a nested class that my class extends. Specifically, it's the getSenderSubID() method in quickfix.fix42.Message.Header. enter image description here

public class ExecutionReport extends Message, and the constructor of Message is:

protected Message(int[] fieldOrder) {
        super(fieldOrder);
        header = new Header(this);
        trailer = new Trailer();
        
        getHeader().setField(new BeginString("FIX.4.2"));
            
    }

The nested Header class is:

public static class Header extends quickfix.Message.Header {

        static final long serialVersionUID = 20050617;

        public Header(Message msg) {
            // JNI compatibility
        }

and the method inside there I want to access is:

    public quickfix.field.SenderSubID getSenderSubID() throws FieldNotFound {
        return get(new quickfix.field.SenderSubID());
    }

To me all of this looks like I should be able to use this method, but it's apparent that I cannot. How could this be?

I double checked that all classes were in package quickfix.fix42; and there were no method overrides in ExecutionReport.


Solution

  • (Not sure what FIX version you're using; I'll say you're using FIX44 for the purposes of this answer. You can adjust accordingly.)

    I think getHeader() is returning a quickfix.Message.Header and not a quickfix.fix44.Message.Header. Only the latter has getSenderSubID().

    Try casting quickfix.Message.Header to quickfix.fix44.Message.Header.