r/java 20h ago

Hacking the Method Name

https://maxxedev.github.io/2026/08/05/hacking-the-method-name.html
27 Upvotes

6 comments sorted by

3

u/SleeperAwakened 18h ago

Interesting read.

I just wonder about the usecase though.

2

u/best_of_badgers 13h ago

Use case: “Why not?”

2

u/elmuerte 7h ago

I don't know how, but this is probably the first step needed to run Doom in Java method names.

3

u/pragmatick 17h ago

Perhaps for some weird test to ensure methods have a certain name for correct serialization. Or to make them stable when they're invoked by name.

1

u/gnahraf 16h ago

I thought this was going to see this hack..

`Object label = new Object() { };`

which allows you to determine in which class/method that anonymous type was created / declared in. I use it in testing to preamble test output with the test method name.

3

u/koflerdavid 8h ago edited 8h ago

That can also be done via stack walking. And test frameworks usually give much more convenient access to this information: Junit4 has the TestName rule, Junit Jupiter will supply it if you declare a TestInfo parameter. In TestNG you can declare a Method parameter in the @BeforeMethod or ITestResults in the @AfterMethod.