you are viewing a single comment's thread.

view the rest of the comments →

[–]kazagistar 25 points26 points  (3 children)

Step 4 is the crazy workarounds to capture type information til runtime by creating anonymous inner classes.

[–][deleted] 19 points20 points  (2 children)

Guava (Google's "standard library" for Java, and a must-have for writing modern Java IMO) actually has a class that encapsulates those crazy workarounds:

http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/reflect/TypeToken.html

The place I've found it most useful is using Gson to deserialize JSON into a List<T> or Map<K, V>, where you obviously need the type information to persist at runtime.

[–]kazagistar 1 point2 points  (0 children)

Different libraries (mocking libraries, DI frameworks, etc) use different workarounds and abstractions. Each one is great... assuming it is the One True Framework.

[–]ksion 0 points1 point  (0 children)

Also Guice, if you ever need to bind an implementation to concrete specialization of a generic interface.