From e152ea4fff2fc96eb9728ed9f03d04febcf80939 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Wed, 11 Oct 2017 08:12:04 +0400 Subject: [PATCH] Add nameOf shortcut for classes --- README.md | 2 +- src/main/java/org/strangeway/nameof/LangUtils.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e857654..a9bc92e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Java nameOfProperty implementation ================================== -Java alternative to nameOf operator. +Java alternative to [nameOf](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/nameof) operator. [![license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](https://api.bintray.com/packages/strangeway-org/libs/nameof/images/download.svg) ](https://bintray.com/strangeway-org/libs/nameof/_latestVersion) diff --git a/src/main/java/org/strangeway/nameof/LangUtils.java b/src/main/java/org/strangeway/nameof/LangUtils.java index fc30d75..c103fa4 100644 --- a/src/main/java/org/strangeway/nameof/LangUtils.java +++ b/src/main/java/org/strangeway/nameof/LangUtils.java @@ -25,6 +25,10 @@ * Utility class that can provide name of bean property using method reference of a getter. */ public final class LangUtils { + public static String nameOf(Class clazz) { + return clazz.getName(); + } + public static String nameOfProperty(Class clazz, Function bridge) { T extractor = PropertyNames.getPropertyNameExtractor(clazz); bridge.apply(extractor);