PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How do I remove the warning from a EasyMock.anyObject(List.class) call

 July 17, 2022     easymock, generics, java, warnings     No comments   

Issue

Compiler can't stop complaining with this call :

EasyMock.anyObject(List.class) 

I tried to specify list's type

EasyMock.anyObject(List<MyType>.class)

but it doesn't seems to be an option (anyway, it is stupid since java will erase the type during the compilation)

Is there a clean way (@SuppressWarning is not a clean way IMO) to remove this warning?

Thank you


Solution

It's not possible. I'll call it a generic limitation. Sadly it's not always possible to remove a warning for some perfectly normal usage (like using the class of a generic class).

However, with EasyMock you can do the following:

EasyMock.<List<MyType>> anyObject()

which will do the same thing but without warning. The anyObject you used exist because it's a bit more readable and allows static imports.



Answered By - Henri Tremblay
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing