“Java Drukuj typ obiektu” Kod odpowiedzi

Java Drukuj typ obiektu

//Example:
Integer number = 15;
System.out.println(number.getClass().getName());

//This print to console the fully qualified name of the class, which for the example is:
java.lang.Integer

//If you want a more concise output, you can use instead:
System.out.println(number.getClass().getSimpleName());

//getSimpleName() give you only the name of the class:
Integer

//Printing the type of primitive variables is a bit more complex: see this 
//https://stackoverflow.com/questions/180097/dynamically-find-the-class-that-represents-a-primitive-java-type
//for details.
Abdulli Woolie

Uzyskaj rodzaj zmiennej Java

((Object) myVar).getClass().getName()
//OR
((Object) myInt).getClass().getSimpleName()
Wide-eyed Weevil

Odpowiedzi podobne do “Java Drukuj typ obiektu”

Pytania podobne do “Java Drukuj typ obiektu”

Więcej pokrewnych odpowiedzi na “Java Drukuj typ obiektu” w Java

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu