A Cute Trick with Generics to Avoid Unwanted Casts

I ran into a cute trick while coding a unit test on a Spring application the other day that I'd like to share.
Consider these lines of Java code. The first line requires a cast.  the reason is that the method returns an Object.  While the cast isn't the most labor intensive construct, but it makes code less clear and is inconvenient to developers.
Note that the second line does *not* require the cast making it much more convenient for developers. the secret is that Sprin...
 •  0 comments  •  flag
Share on Twitter
Published on July 20, 2016 06:43
No comments have been added yet.