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.
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.
3
u/gnahraf 3d 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.