Home java How to see the type of java variable?

How to see the type of java variable?

Author

Date

Category

I understand that in Java “strict typing”. However, if for example, I made a lot of deliveries in the code and I want to bring the type of variable at the end, how can I do it?

Here is an example in JavaScript and python

var a = 5;
Typeof (A);
// if you bring the last time, the answer will be - Integer
print (type (Object))

Answer 1, Authority 100%

If you need to display the type of primitive variable (Int, Double, Long …), then it seems like in Java is not possible. But you can easily find out what kind of class you use.

yourclass.getclass (). getname ();

It will show you the name of the class in the form (com.company.example.yourclassname), or you can use:

yourclass.getclass (). GetSimpleName ();

This returns exceptionally the name of the class. And if you need to check if it is assumed whether the variable string is useful as follows:

if (s instanceof string)

Instead of String, you can put any class that you need.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions