Quantcast
Channel: Java – Dark Views
Viewing all articles
Browse latest Browse all 15

There is no Spoon: Changing Final Fields in Java

$
0
0

If you’re the guy in the team who solves the impossible problems, you will eventually run into the worst of all design patterns: Singletons. Which are implemented in Java using final (static) fields.

Sebastian Zarnekow came up with a way to change that. Following the timeless advice from the Matrix – there is no spoon -, he found a way to modify (some) final fields.

As I said before, this is a desperate measure, so use it wisely. But remember this tool next time when you need to mock a singleton for a test case.


Tagged: Design Patterns, Java, Singleton

Viewing all articles
Browse latest Browse all 15

Trending Articles