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

Related tags

Spring Boot nameof
Overview

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.

You might also like...

Z is a Java library providing accessible, consistent function combinators.

Fearless function combination in Java Techniques Unlock your functional programming potential with these combination techniques: Fusion Z.fuse(fn1, fn

Jun 13, 2022

This is a small library written in Java for minecraft login.

minecraft-auth-library This is a small library written in Java for minecraft login. Usage: Login with microsoft MinecraftAuthenticator minecraftAuthen

Feb 5, 2022

SpringBoot show case application for reactive-pulsar library (Reactive Streams adapter for Apache Pulsar Java Client)

Reactive Pulsar Client show case application Prerequisites Cloning reactive-pulsar Running this application requires cloning https://github.com/lhotar

Nov 10, 2022

A bitcoin explorer Java library that utilizes multiple data sources at once.

Bitcoin Explorer A bitcoin explorer library that utilizes multiple data sources at once. Branch Build Unit Tests master development Table of Contents

Jan 31, 2022

A lightweight messaging library that simplifies the development and usage of RabbitMQ with the AMQP protocol.

kryo-messaging This library contains a simple MessagingService which simplifies the setup and work with RabbitMQ and the AMQP protocol. Usage Gradle r

Jan 10, 2022

A networking library for LibGDX utilizing Netty allowing easy creation of multiplayer games.

Lunar What is Lunar? Lunar is a networking library for LibGDX. With lunar you can easily create multiplayer games quickly and efficiently. Lunar provi

Nov 25, 2022

A complete and performing library to highlight text snippets (EditText, SpannableString and TextView) using Spannable with Regular Expressions (Regex) for Android.

A complete and performing library to highlight text snippets (EditText, SpannableString and TextView) using Spannable with Regular Expressions (Regex) for Android.

Highlight A complete and performing library to highlight text snippets (EditText/Editable and TextView) using Spannable with Regular Expressions (Rege

Dec 22, 2022

A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Nov 29, 2022

Nrich is a Java library developed at CROZ whose purpose is to make development of applications on JVM a little easier.

nrich Nrich is a Java library developed at CROZ whose purpose is to make development of applications on JVM a little easier. It contains modules that

Nov 12, 2022
Owner
MoebiusCode
MoebiusCode
Library for converting from one Java class to a dissimilar Java class with similar names based on the Bean convention

Beanmapper Beanmapper is a Java library for mapping dissimilar Java classes with similar names. The use cases for Beanmapper are the following: mappin

null 26 Nov 15, 2022
Java Deferred/Promise library similar to JQuery.

JDeferred 2.x JDeferred is a Java Deferred/Promise library similar to JQuery's Deferred Object. Inspired by JQuery and Android Deferred Object. If you

JDeferred 1.5k Dec 29, 2022
Java library to perform reverse Domain Name Service (rDNS) lookups with ease.

ipregistry-rdns Java library to perform reverse Domain Name Service (rDNS) lookups with ease. The library is async, thread-safe and has built-in suppo

Ipregistry 2 Jul 18, 2022
CIRCUS - a Java and Spring Boot application for creating rooms with the purpose of watching YouTube videos together, similar to Watch2Gether

CIRCUS Video rooms application built using Apache Kafka, Java, Spring Boot, Spring Security and PostgreSQL About CIRCUS is a Java and Spring Boot appl

Castanho Correia 1 Jun 5, 2022
Similar to the minimap application, this program gets information from the center of the screen and displays information about that creature from a database.

New-World-CreatureInfo Similar to the minimap application, this program gets information from the center of the screen and displays information about

Mal Ball 2 Sep 21, 2022
GodType is a very simple Bukkit plugin to allow the console (or a player) to chat as a defined name.

GodType GodType is a very simple Bukkit plugin to allow the console (or a player) to chat as a defined name. Config A config.yml file will be created

null 1 Dec 24, 2021
Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Hayden Hanson 0 May 21, 2022
A proper Name Spoofer mod for Minecraft Forge 1.8.9.

Name-Spoofer Change ANY text displayed on your screen visually. *It does not actually change any strings and is client side (If you spoof a 1 characte

Exploration 3 Dec 15, 2022
A powerful API whichs allows developers to change a players name and UUID on login.

UUIDSwitcher An easy to use but powerful API for spigot servers which gives developers control over the UUID and name a player logs in with. This chan

BeefDev 6 Nov 30, 2022
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.

Tinker Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk. Getting started Add t

Tencent 16.6k Dec 30, 2022