Ahmet Ekrem SABAN
asked on
Java generics error
Hello!
I need your help because of a problem is a generics code. I reduced the problem to a test case. The code comprises of a class that is to be tested with JUnit, and the associated JUnit test case.
Something is wrong in my code, as the last line in the JUnit test fails. The Debugging class has a method that prints the content of a list:
The list has elements after the method is called, and the contents are printed out by the printContent method as follows:
generics.DataServiceTest$T rainClassD to@24e8607 3 generics.DataServiceTest$T rainClassD to@141430f 3 generics.DataServiceTest$T rainClassD to@3999abd 1 generics.DataServiceTest$T rainClassD to@17df43e 2 generics.DataServiceTest$T rainClassD to@42e1b6a c
What I can't see is the error that results in the names of the DTO (data transfer object) objects instead of their contents. If their contents would have been translated, the 0. element would start with the ID of 1, which would make the second test case true.
Thank you for your help!
DataService.java
DataServiceTest.java
I need your help because of a problem is a generics code. I reduced the problem to a test case. The code comprises of a class that is to be tested with JUnit, and the associated JUnit test case.
Something is wrong in my code, as the last line in the JUnit test fails. The Debugging class has a method that prints the content of a list:
/**
* Prints the content of the vector.
*
* @param <T> the generic type
* @param list the vector
*/
@SuppressWarnings("unchecked")
public static <T> void printContent(final List<T> list) {
for (final T element : list) {
if (element instanceof List) {
printContent((List<T>) element);
} else {
System.out.print(element);
System.out.print(' ');
}
}
System.out.println();
}
The list has elements after the method is called, and the contents are printed out by the printContent method as follows:
generics.DataServiceTest$T
What I can't see is the error that results in the names of the DTO (data transfer object) objects instead of their contents. If their contents would have been translated, the 0. element would start with the ID of 1, which would make the second test case true.
Thank you for your help!
DataService.java
DataServiceTest.java
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
ASKER