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