Java tutorial
//package com.java2s; //License from project: LGPL import javax.xml.bind.annotation.XmlRootElement; import java.util.Optional; public class Main { private static <T> String elementNameFrom(final Class<T> clazz) { return Optional.ofNullable(clazz.getAnnotation(XmlRootElement.class)).map(XmlRootElement::name) .orElseGet(clazz::getSimpleName); } }