Hacker News new | ask | show | jobs
by mrkeen 579 days ago
> So now we cannot easily mock final classes in tests

> And mocking tools have to resort to bytecode manipulation to mock the final classes

Well which is it? Presumably you use said mocking tool anyway, so it's not your effort that's being expended.

"Final all the things" really doesn't go far enough. There is little point substituting a mutable hashmap for a "final" mutable hashmap, when the actual solution is for the standard library to ship proper immutable collection classes.

In any case, I prefer to avoid mockito anyway, so it's a non-issue for me. Just do plain ol' dependency injection by passing in dependencies into constructors.

1 comments

As I mentioned in another reply, Josh Bloch experimented with a different type structure for the Collections API that could have yielded read only collections but he thought it was too confusing and went back to… this.

And I’ve never forgiven him for it