When do Java generics require

Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected = null; Map<String, Class<java.util.Date>> result = null; assertThat(result, is(expected)); This does not compile with the JUnit assertThat method signature of: public static <T> void assertThat(T actual, Matcher<T> matcher) The compiler error message is: Error:Error:line (102)cannot find symbol method assertThat(java.util.Map<java.lang.String,java.lang.Class<java.util.Date>>, org.hamcrest.Matcher<java.util.Map<java.lang.String,java.lang.Class <? … Read more

What does the question mark in Java generics’ type parameter mean? [duplicate]

This question already has answers here: Generic list type with question mark [duplicate] (5 answers) Closed 11 months ago. This is a small snippet of code taken from some of the examples that accompany the Stanford Parser. I’ve been developing in Java for about 4 years, but have never had a very strong understanding of … Read more

convert a list of objects from one type to another using lambda expression

I have a foreach loop reading a list of objects of one type and producing a list of objects of a different type. I was told that a lambda expression can achieve the same result. var origList = List<OrigType>(); // assume populated var targetList = List<TargetType>(); foreach(OrigType a in origList) { targetList.Add(new TargetType() {SomeValue = … Read more