Skip to content

Searching for final methods in a Java project

Sébastien Dubois / May 23, 2019

1 min read

Quick tip of the day: searching for final methods in a Java project.

Recently at work, I had to find all final methods in a codebase.

The following regular expression helped me out:

(public|protected|private|static|\\s) (final) +\[\\w\\<\\>\\\[\\\]\]+\\s+(\\w+) \*\\(\[^\\)\]\*\\) \*(\\{?|\[^;\])

For the curious among you, I needed to do this because of an issue where some Spring bean mysteriously had null properties. The issue was caused by the fact that we had final methods in some beans that CGLib did not like (i.e., could not proxy).

That’s it for today 😉

PS: check out the Dev Concepts collection of e-books, join the Software Crafters community, the Personal Knowledge Management community, and come say hi on Twitter!
Discuss on TwitterEdit on GitHub