Why does Matcher and BaseMatcher use generics?

70 views
Skip to first unread message

Andrew Maxwell

unread,
Nov 28, 2016, 12:08:34 PM11/28/16
to Hamcrest Java Users
I have just written a couple of matchers extending BaseMatcher, but when looking at the Matcher and BaseMatcher code, I started to wonder why the class/interface were generic?

I haven't used T in my subclasses of BaseMatcher because the type parameter isn't used anywhere in either the class or the object and I didn't want to unnecessarily clutter up the code, but I was interested to know if there was any reason if I should put it back in?

TIA!


Steve Freeman

unread,
Nov 28, 2016, 12:23:46 PM11/28/16
to hamcre...@googlegroups.com
Glad to hear from an active user.

Two reasons: one was to catch any errors that could be detected by the type system, so that some changes could be highlighted immediately; the other was for use with jMock, so that expectations would work with production method signatures.

Given this is local, it's up to you to see what works. The obvious cases shouldn't really clutter the code up much, but propagate through.

S
> --
> You received this message because you are subscribed to the Google Groups "Hamcrest Java Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hamcrest-jav...@googlegroups.com.
> To post to this group, send email to hamcre...@googlegroups.com.
> Visit this group at https://groups.google.com/group/hamcrest-java.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages