Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting only name of the class Class.getName()

Tags:

java

class

How can i get the name of the class

String.class.getName()  returns java.lang.String 


I am only interested in getting last part ie only String
Any Api can do that?

like image 545
akshay Avatar asked Jul 21 '11 14:07

akshay


People also ask

What does getName () do in Java?

getName() returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.

How do you return a class name in Java?

The simplest way is to call the getClass() method that returns the class's name or interface represented by an object that is not an array. We can also use getSimpleName() or getCanonicalName() , which returns the simple name (as in source code) and canonical name of the underlying class, respectively.

How do I find the class name for a String?

String className = this. getClass(). getSimpleName(); This will work as long as you don't use it in a static method.

How do I get the class name of an object in Python?

To get the class name of an instance in Python: Use the type() function and __name__ to get the type or class of the Object/Instance. Using the combination of the __class__ and __name__ to get the type or class of the Object/Instance.


1 Answers

Class.getSimpleName()

like image 50
andyb Avatar answered Nov 15 '22 14:11

andyb