Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 3
    is it just me or you need to provide an example of what you want to achieve?
    – Eugene
    Commented Jun 15, 2017 at 9:25
  • 5
    I’m afraid, this is impossible. On the other hand, if you are inside the method, you already know the method, its signature and so on. Using this information directly hinders copy&paste programming or Refactoring, but these should not be your main development styles anyway. —Oh well, if you could do this for the caller, it would perhaps enable developing some neat tools, however, it is not supported by the standard API, not even Java 9’s stack walker…
    – Holger
    Commented Jun 15, 2017 at 9:48
  • @Eugene : Here you go.
    – Zsar
    Commented Jun 15, 2017 at 10:08
  • 1
    The use case doesn’t cover the actual use case, i.e. the potential caller(s) of these methods. There is a trick, how callers could get to their own Method object if performance doesn’t matter, but if all you want, is the parameter name, and you’re even introducing a dependency to the parameter position at the same time, it doesn’t make much sense. Isn’t Objects.requireNonNull(myParam, "myParam") cleaner and simpler than MyAssertions.notNull(myParam, 42)? Especially, as the latter only provides a name if the method has been compiled with a special option to retain method parameter names?
    – Holger
    Commented May 23, 2022 at 15:56