anyList with specified type?

4,453 views
Skip to first unread message

rogerdpack

unread,
Sep 1, 2016, 3:12:00 PM9/1/16
to mockito
Seems something changes with "anyList"

This line compiled with 2.0.53-beta

verify(subject).methodName((List<String>) isNull(), anyList());

but with 2.0.111-beta

I get this:

Error:(222, 80) java: incompatible types: java.util.List<java.lang.Object> cannot be converted to java.util.List<org.X.Y>

How do I add "type" to the anyList() ? Sorry my java-fu isn't up to par for the generics there.

I would have just changee it to anyListOf but that is deprecated [speaking of which, what is the "replacement" for java 8 supposed to be? just wondering].

Thanks!
-roger-

Brice Dutheil

unread,
Sep 1, 2016, 6:42:51 PM9/1/16
to mockito
Hi rogerdpack,

Java 8 compiler is smarter and can infer the generic of the returned type, so in Java 8 the favored will just be anyList.

For Java 6/7 the preferred way is anyListOf, using anyList requires to cast.
I understand this may be troublesome but not doing this imposes to bring along the issues of older JDK to the new one.

For the deprecation the javadoc says it should be removed in mockito 3. Not deprecating them is wrong.

However I have a idea : Having a matcher API class that work better with Java 6 runtime. This class would of course disappear with Mockito 3 (Java 8 requirement).

By the way thanks for the feedback!

-- Brice




--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/d9ea8c10-ba5a-45a0-9897-ce78bcfc50b1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages