Q&A Highlights

Over the years I’ve enjoyed answering questions on StackOverflow and related sites, and feel it’s a decent way to get to know my knowledge, writing style, and development philosophy.

As of February 2024, I am in StackOverflow’s top 1500 contributors or top 0.2% (by reputation points). I am one of two gold badge contributors to dagger-2, and I am the sole gold badge contributor on the topics of guice and mockito. Based on pageviews to my highly-ranked answers, StackOverflow has estimated my total impact as reaching ~8 million people.

Android

A: ClassCastException: Application object is not my custom application object

In this question, an API-level-specific Android runtime bug caused some confusing behavior. A quick comment on the question wound up solving the mystery and saving some tricky debugging time for the developer.

A: AndroidX Dagger2 MultiDexApplication: Does not implement HasActivityInjector

This question expands on a quick answer—a missing XML label—to cover best-practices regarding lightweight Application subclasses. The answer also alludes to the diagnosis; some of the fun in StackOverflow is in using incomplete or imprecise information to debug the problem remotely.

A: How do you cast RuntimeEnvironment.application?

This question presents a seemingly-nonsensical error message: RoboApplication cannot be cast to RoboApplication. However, the error message is useful, since PowerMock and Robolectric each use their own class-modifying classloaders. This answer discusses the root cause along with some testing alternatives.

Dagger / Guice

A: What is dagger exactly, and how it works

This question is a basic overview, but shows how I try to make long-lived documentation through well-strucured writing. StackOverflow answers provide a great opportunity to practice answering questions that can adapt to a wide range of levels of expertise.

A: Does Guice binding bind subclass as well?

This is a question about Guice basics, but one where things accidentally appear to work. Clarifying these basics can make all the difference when learning complex frameworks.

A: Why use/develop Guice, when You have Spring and Dagger?

This is a closed question: The community decided that this kind of question is difficult to answer in an unbiased way. I’m flattered with the reception the question has received since then, and I’d like to think a little insight into DI history would help readers make informed framework choices.

A: Accessing Guice injector in its Module?

Guice modules are an unusual mix of declarative configuration and procedural code. One of my well-appreciated answers turns a well-intentioned antipattern into a cookbook of clean alternatives.

A: Dagger @Reusable scope vs @Singleton

Dagger’s relatively-new @Reusable annotation provides a pragmatic approach to instance reuse. The difference is small, but that nuance allows for powerful options—especially on Android.

Javascript / TypeScript

A: How to know when all Promises are Resolved in a dynamic “iterable” parameter?

Promises are an extremely powerful addition to Javascript, and their features can be hard to master. Here, a short utility function (10 lines of code) can neatly solve a self-contained problem, while also demonstrating Promises returning Promises. I also supplied documentation comments and a concise test harness to demonstrate whether and how the solution works.

Deliberately written with ES5 features and syntax for maximum reuse.

A: Throttle amount of promises open at a given time

This collaborative answer solves the initial problem, including a clarification about promises vs promise factories.

A: Typescript: Expand existing function definition

TypeScript has some impressive hidden utility types within its standard library. Here, Parameters<T> and ReturnType<T> allow can help to make flexible definitions with a minimum of repetition.

Mockito

Q&A: How do Mockito Matchers Work?

This is a self-answered question: I had seen several questions before about how Mockito’s syntax can trip up reasonable-looking usage, and wanted to write one clear and easy-to-find answer to put into a community-curated place. Despite the larger scope, this question and answer have each received hundreds of positive votes, and over 100,000 views.

A: Mockito runnable: wanted but not invoked?

I happened to see this question right as it was posted, and could very quickly point out how Java’s anonymous inner class syntax and Mockito’s clever subclassing could combine to cause some counterintuitive test behavior. “I would never have found that in a million years,” question asker Jon O. replied.

A: Mockito verify after exception Junit 4.10

Before Java 8 brought lambda syntax to Java, assertThrows-style assertions were difficult to get right, and tools like ExpectedException were popular alternatives. This answer explains how ExpectedException works behind the scenes and shows where a tried-and-true Java idiom still provides value.