Difference between casting to String and String.valueOf

前端 未结 8 2115
轮回少年
轮回少年 2020-12-02 12:10

What is the difference between

Object foo = \"something\";
String bar = String.valueOf(foo);

and

Object foo = \"something\"         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 12:18

    Both generates same output in case of String.

    Casting fails in case of provided object is Not a string.

提交回复
热议问题