Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6054525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:09:46+00:00 2026-05-23T08:09:46+00:00

An answewr on this thread suggested using anyCollectionOf() however I cannot get it to

  • 0

An answewr on this thread suggested using anyCollectionOf() however I cannot get it to work
Mockito: Verifying with generic parameters

I have a Generic Class for holding two “versions” of the same object for comparison purposes

public class ChangedVO<T> {

private T before;
private T after;

/*** Constructors ***/

public ChangedVO() {}

public ChangedVO(T before, T after) {
    this.before = before;
    this.after = after;
}

/*** Getters & setters ***/

...
}

Now in my UnitTest the following code “does” work…

verify(emailService, never()).sendBookChangesEmail(Matchers.<List<ChangedVO<BookVO>>>any());

…however I’m interested to know how the same thing can be achieved using anyCollectionOf() ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:09:46+00:00Added an answer on May 23, 2026 at 8:09 am

    Interesting use of Mockito with generics. The only way I think you can use anyListOf() in this situation is by typing

    verify(emailService, never()).sendBookChangesEmail(anyListOf((Class<ChangedV0<BookV0>>) null));
    

    Instead of passing a class instance you pass it null. This is not how the documentation says you shoud use anyListOf() but in this specific situation it seems to work.

    The problem is generic type erasure in Java which makes that you can not differentiate between an instance of

    Class<ChangedV0<BookVO>> or
    Class<ChangedV0>
    

    during runtime and therefore there is no way you can create anything that statically conforms to

    Class<ChangedV0<BookVO>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this in my view: form_for [:support, @thread, @reply], url: support_thread_replies_path do |f|
i have followed the answer to this thread C# import excel filesheet to sql
I almost found the answer to this question in this thread (samplebias's answer); however
I am really hoping to get a definitive answer to this. I have a
This thread in SO is about multidimensional array in c+ +. I have to
I have written an HttpModule that spawns a background thread. I'm using the thread
I got a comment to my answer on this thread: Malloc inside a function
I'm intrigued by this answer from another SO thread, and I was hoping someone
[Note: There is another thread about this problem but it did not answer the
Before you answer this I have never developed anything popular enough to attain high

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.