Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generic way of getting class name

Tags:

java

Would what be a static equivalent of a dynamic

String CLASS_NAME = this.getClass().getCanonicalName()

Note that the following is not what i'm looking for since it specifically refers to a particular class. I'd like to refer to class name outside of a method (ie in the static {} section)

static String CLASS_NAME = Foo.class.getCanonicalName()

THanks.

like image 218
Saideira Avatar asked Aug 09 '11 16:08

Saideira


People also ask

How do I find my generic class name?

You can see that in the main method, or in any instance method, I am capable to get the name of the generics type, in this case the main will print: java. lang. Integer. ...and you get the name of the subclass (if any).

What is the generic class type called?

Generic Classes These classes are known as parameterized classes or parameterized types because they accept one or more parameters.

What is generic class with example?

A Generic class simply means that the items or functions in that class can be generalized with the parameter(example T) to specify that we can add any type as a parameter in place of T like Integer, Character, String, Double or any other user-defined type.

How do I find the class name of an object?

If you have a JavaSW object, you can obtain it's class object by calling getClass() on the object. To determine a String representation of the name of the class, you can call getName() on the class.


1 Answers

Not sure if I understand your question - did you try this.getClass().getCanonicalName()?

like image 173
home Avatar answered Oct 20 '22 17:10

home