开发者

Where is Short.toString(short s, int radix)?

Short.parseShort(String s, int radix) exists, as does Integer.parseInt(String s, int radix) and Long.parseLong开发者_开发技巧(String s, int radix).

Integer.toString(int i, int radix) and Long.toString(long l, int radix) exist.

Short.toString(short s), Integer.toString(int i) and Long.toString(long l) all exist.

So why is there no Short.toString(short s, int radix)?

(It can't be because you can always cast your short to an int and use the Integer class' method, the same argument could be made for getting rid that; you could always cast your int to a long and use the Long class' version.)


Take a look at the implementation of Short.toString(short s):

public static String toString(short s) {
    return Integer.toString((int)s, 10);
}

So, just use Integer. (Note that the implementation is different for Integer and Long)


The arguement is that you can use the Integer.toString(int, int)!

Looking at the code for Short.toString(short) (Java 6), it uses the Integer version under the covers:

public static String toString(short s) {
     return Integer.toString((int)s, 10);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜