I am trying to write JUnit tests for my expression tree. The tree consists of BaseExpressionTree <ValueType> (terminal nodes), ExpressionOperator <T> (nonterminal nodes) and CompositeExpressionTree <ValueType> (Sub Trees).
The data structure is assumed to be compatible with String, Double, and List <String> or List <Double> as the base expression (terminal output).
Classes are implemented using generics. There were no problems with the Double and String implementations, however the List <String> and List <Double> implementations lead to conflicts with Generics.
The heart of the problem is the ListOperator constructor. ListOperator is designed to represent operations on structures such as ArrayList and LinkedList. I would like to declare the class as follows:
public class ListOperator<List<T>> implements ExpressionOperator<List<T>>{
...
but I can only declare it as follows:
public class ListOperator< T> implements ExpressionOperator<List<T>>{
private ExpressionOperator<T> scalarOperator;
public ListOperator (ExpressionOperator<T> operator){
this.scalarOperator=operator;
}
}
basically the <T> in the ListOperator (which is a List) contradicts the <T> in the ExpressionOperator (which should represent what is inside the list).
Eclipse gives the following error output:
The constructor ListOperator<List<Double>>(DoubleOperator) is undefined
Is there a solution that does not involve the use of wild cards? The homework instructions were clear enough that the general definition of classes is how they were described in the tooltip.
I can use wild cards in the constructor options, but so far I have not been able to do this.
public ListOperator (? extends ExpressionOperator<T> operator){
and
public ListOperator (< ? extends ExpressionOperator<T>> operator){
both give errors.