SkillAgentSearch skills...

Nameof

Library to programatically return the name of fields similar to the C# nameof operator

Install / Use

/learn @mobiuscode-com/Nameof
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

nameof()

Maven Central

A Java library to programmatically return the name of fields similar to the C# nameof expression

How to use?

The library is part of the Central Repository and can simply be used like this:

Maven

<dependency>
    <groupId>de.mobiuscode.nameof</groupId>
    <artifactId>nameof</artifactId>
    <version>1.0</version>
</dependency>

Gradle

implementation 'de.mobiuscode.nameof:nameof:1.0'

Example

If you have a Java Bean like this:

public class User {
  private String userName;

  private String firstName;
  private String lastName;

  public String getUserName() {
    return userName;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }
}

you can use this method to get the name of a field by its getter:

Name.of(User.class, User::getFirstName);

This will return the string "firstName", just like the C# expression nameof(firstName) would do.

This is particularly handy in case you are refactoring the name of that field, because then the name of the getter would also be adjusted and with it the Name.of() method would return the new field name.

Related Skills

View on GitHub
GitHub Stars20
CategoryDevelopment
Updated1mo ago
Forks1

Languages

Java

Security Score

90/100

Audited on Feb 27, 2026

No findings