0
List<Restriction> restrictions = new ArrayList<>();
//list operation.......
when(restrictionUpdator.executeBatch(anyInt(), 
                                     any(List.class), 
                                     any(RequestorInfo.class),
                                     (Class<Obj>) any())
     ).thenReturn(restrictions);

excuteBatch method:

public <T extends Obj> List<T> executeBatch(int Id, 
                                                List<UpdateContext> contexts,
                                                RequestorInfo requestor, 
                                                Class<T> tClass)

Class:

public class Restriction extends Obj

Can someone have a look?
Why above code has compiler error in IDE language 8?
If I change IDE language 8 to 7, it is back to normal and build success.

Haven Lin
  • 176
  • 1
  • 16
  • 4
    **WHICH** error? – JB Nizet May 25 '17 at 11:11
  • @JBNizet Cannot resolve method 'thenReturn(java.util.List)' – Haven Lin May 25 '17 at 11:14
  • Well, the last argument, declared as Class, is of type Class. So executeBatch is supposed to return a List, i.e. a List. But you make it return a List. – JB Nizet May 25 '17 at 11:17
  • @JBNizet Restriction extend Obj, why should be not return List? it works well in language level 7 – Haven Lin May 25 '17 at 11:20
  • 1
    Now you've changed your code... So my previous explanation doesn't stand anymore. But the explanation for the new code is the same: your method is supposed to return a List, since you're passing a Class, and the generic type T is thus inferred as Obj. A List is NOT a List. See https://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-arent-javas-generics-implicitly-p – JB Nizet May 25 '17 at 11:24
  • 1
    Please edit your question to add that information. – Mark Rotteveel May 25 '17 at 11:25
  • what about replacing ` (Class) any())` by `any(Class.class). Even if it would compile (e.g. by changing it to `(Class) any()`, it would not run in the old way. – CoronA May 25 '17 at 11:33
  • @CoronA finally, i used (Class) any() – Haven Lin May 26 '17 at 10:35

0 Answers0