Search code examples
javavariablestypesdynamictype

is there a keyword in java that's similar to swift's dynamicType


I know that in swift, there is a keyword called variableName.dynamicType which identify the type of which the variable belongs to. I was just wondering if there is a similar keyword in java?


Solution

  • There is Object#getClass (which gives you a java.lang.Class):

     Object x = new BigInteger(123);
     System.out.println(x.getClass().getSimpleName());