Is there a way to output the java data type to the console?

后端 未结 5 1209
灰色年华
灰色年华 2021-01-31 15:02

I\'m trying to debug a program I inherited. This program contains Strings, array lists and collections, lots of casting between types, and I need to do some String manipulations

5条回答
  •  囚心锁ツ
    2021-01-31 15:29

    instance.getClass() is the way to go if you just want to print the type. You can also use instanceof if you want to branch the behaviour based on type e.g.

    if ( x instanceof String )
    {
       // handle string
    }
    

提交回复
热议问题