I wrote my first generic Java method; whee. There was one mystery there: Book is a subtype of Entity, and at one point, I passed a Collection<Book> to a function expecteding a Collection<Entity>, and it worked. But then I did the same with a Collection<Series> (where Series is another subtype of Entity), and it didn’t work. I understand the latter, but not the former; is it a bug, or am I missing something? Anyways, making the method generic, expecting a Collection<T extends Entity>, worked fine, as expected.
I also got rid of a legacy exception that was annoying me; I’m still not at peace with Java exceptions, and there’s no sense doing extra typing because of code I don’t need any more. I did give in and pass a Collection where I would have liked to use an Iterator, though…
Hmm. Now I’m starting to wonder: exceptions and generics are both places where Java is statically typed and C++ is dynamically typed; in both cases, I like the C++ solution. I really should try a dynamically typed language sometime soon; maybe once I do that I’ll switch back to the dynamic typing crowd.
There are no revisions for this post.