Nameof
Library to programatically return the name of fields similar to the C# nameof operator
Install / Use
/learn @mobiuscode-com/NameofREADME
nameof()
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
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
