“Dapatkan jenis variabel java” Kode Jawaban

Periksa jenis java variabel

public class MyClass {
    public static void main(String args[]) {
        int x = 5;
        System.out.println(((Object)x).getClass().getSimpleName());

    }
}
Defiant Dove

jenis objek java cetak

//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

Dapatkan jenis variabel java

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

Dapatkan Java Tipe

a.getClass().getName()
Malario

Jawaban yang mirip dengan “Dapatkan jenis variabel java”

Pertanyaan yang mirip dengan “Dapatkan jenis variabel java”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya