(String) or .toString()?

后端 未结 9 1533
慢半拍i
慢半拍i 2020-12-12 16:56

I have a method with an Object o parameter.

In this method, I exactly know there is a String in \"o\" which is not null. There is no need t

9条回答
  •  攒了一身酷
    2020-12-12 17:23

    According to Silly performance musings: x.toString() vs (String)x

    In thend end, results are surprisingly clear: it is at least twice as fast to cast Object to String than to call Object.toString()

提交回复
热议问题