Answers for "type of java object"

2

how to check object type in java

// obj instanceof Class

/*example*/

String str = "a String made by the String class";

if(str instanceof String) System.out.println("This is True");
if(str instanceof float) System.out.println("This will never be on your screen");

// You can do this with any type of class you want!
Posted by: Guest on March-19-2021
0

java typeof

Object obj = null;
obj = new ArrayList<String>();
System.out.println(obj.getClass());

obj = "dummy";
System.out.println(obj.getClass());

obj = 4;
System.out.println(obj.getClass());
Posted by: Guest on November-08-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language