Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Generics and JMock

Thread view: 
Owen Jacobson - 13 Dec 2007 05:27 GMT
An open challenge for the newsgroup at large, while I'm thinking about
this:

I'm trying to use JMock to create a mock instance of a generic
interface (EventDispatcher<T>).  This is, quite obviously, the eight-
lane-express highway to hell, since generics and mockery do not mix in
any way.

While it's correct,
 EventDispatcher<Foo> fooMock = mock (EventDispatcher.class)
generates an unchecked cast warning, which is ugly.  Harmless, but
ugly.  The challenge is to create a type signature for mock(Class c)
that allows this to succeed without warnings without allowing
nonsensical mocks like

String mockString = mock (CharSequence.class)

.

My initial attempt was this signature, which allows both the former
and the latter:

 <C, T extends C> T mock (Class<C> c)

Any thoughts?
-o
Roedy Green - 14 Dec 2007 16:58 GMT
On Wed, 12 Dec 2007 21:27:20 -0800 (PST), Owen Jacobson
<angrybaldguy@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>My initial attempt was this signature, which allows both the former
>and the latter:

I usually start to splutter with rage at trying to solve these
problems.  Generics are supposed to make coding safer not more hideous
and complicated.  There is something fundamentally wrong with generics
when it starts requiring these sorts of gavottes.

My usual tactic is to scan the code in src.zip for source code similar
to what I am trying to do, then puzzle why the Sun code works, then
copy the technique.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.