/** * Returns either backtick-quoted `named.getName()` (if `named` not null), * or "[null]" if `named` is null. * * @since 2.9 */ public static String nameOf(Named named) { if (named == null) { return "[null]"; } return backticked(named.getName()); }
/** * Returns either `cls.getName()` (if `cls` not null), * or "[null]" if `cls` is null. * * @since 2.9 */ public static String nameOf(Class<?> cls) { if (cls == null) { return "[null]"; } int index = 0; while (cls.isArray()) { ++index; cls = cls.getComponentType(); } String base = cls.isPrimitive() ? cls.getSimpleName() : cls.getName(); if (index > 0) { StringBuilder sb = new StringBuilder(base); do { sb.append("[]"); } while (--index > 0); base = sb.toString(); } return backticked(base); }
/** * Returns either backtick-quoted `named.getName()` (if `named` not null), * or "[null]" if `named` is null. * * @since 2.9 */ public static String nameOf(Named named) { if (named == null) { return "[null]"; } return backticked(named.getName()); }
/** * Returns either `cls.getName()` (if `cls` not null), * or "[null]" if `cls` is null. * * @since 2.9 */ public static String nameOf(Class<?> cls) { if (cls == null) { return "[null]"; } int index = 0; while (cls.isArray()) { ++index; cls = cls.getComponentType(); } String base = cls.isPrimitive() ? cls.getSimpleName() : cls.getName(); if (index > 0) { StringBuilder sb = new StringBuilder(base); do { sb.append("[]"); } while (--index > 0); base = sb.toString(); } return backticked(base); }