Java examples for JNDI:Name
Getting the Name of a Member Object
import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class Main { public static void main(String[] args) { Class cls = java.lang.String.class; Method method = cls.getMethods()[0]; Field field = cls.getFields()[0]; Constructor constructor = cls.getConstructors()[0]; String name;/*from ww w . j ava 2 s . c o m*/ // Fully-qualified names name = cls.getName(); // java.lang.String name = cls.getName() + "." + field.getName(); // java.lang.String.CASE_INSENSITIVE_ORDER name = constructor.getName(); // java.lang.String name = cls.getName() + "." + method.getName(); // java.lang.String.hashCode // Unqualified names name = cls.getName().substring(cls.getPackage().getName().length() + 1); // String name = field.getName(); // CASE_INSENSITIVE_ORDER name = constructor.getName().substring( cls.getPackage().getName().length() + 1); // String name = method.getName(); // hashCode } }