I have the following class

```
public class Expression<T> {
    private T expression;

    public Expression (T expression) {
        this.setExpression(expression);
    }

    // getters and setters
}

```

and multiple types that look like this

```
public class Load {
    private Variable memory;
    private Variable address;
    private long size;

    // constructor, getters and setters
}

```

and another one that takes both Expressions and Variables:

```
public class Def {
    private Variable lhs;
    private Expression<?> rhs;

    public Def(Variable lhs, Expression<?> rhs) {
        this.setLhs(lhs);
        this.setRhs(rhs);
    }
}

```

Now I would like to create definitions of different Expression types, such as Load, Store etc.
However, I will only know at runtime what type of Expression it will be and all those subtypes only store the variables and do not have any other methods than getters and setters.

I have a function that checks what the current Expression type is and this function has multiple return types Expression. I was not able to figure out how to define such a function.
Here is one attempt, however, I can only extend one class:

```
protected Expression<? extends Load> createExpression(PcodeOp pcodeOp) {

    Varnode[] inputs = pcodeOp.getInputs();
    String mnemonic = pcodeOp.getMnemonic();

    if(mnemonic == "LOAD") {
        Expression<Load> loadExp = new Expression<Load>();
        return loadExp;
    } 
    else if(mnemonic == "STORE") {
        Expression<Store> storeExp = new Expression<Store>();
        return storeExp;
    }
    else if(mnemonic == "PIECE") {
        Expression<Concat> concatExp = new Expression<Concat>();
        return concatExp;
    }
    else if(mnemonic == "SUBPIECE") {
        Expression<Extract> extractExp = new Expression<Extract>();
        return extractExp;
    }
    else if(isBinOp(mnemonic)) {
        Expression<BinOp> binOpExp = new Expression<BinOp>();
        return binOpExp;
    }
    else if(isUnOp(mnemonic)) {
        Expression<UnOp> unOpExp = new Expression<UnOp>();
        return unOpExp;
    }
    else if(isCast(mnemonic)) {
        Expression<Cast> castExp = new Expression<Cast>();
        return castExp;
    }
}

```

This function in still incomplete as I still have to add all Variables to each type.

I am relatively new to Java and haven't found any other good implementation yet. If someone knows a better way to implement that, I'd be happy to hear that.