我有几个与这些包装类的方法有关的问题。
首先,为什么 Long(或 Integer)方法在 valueOf 方法中将 String 作为参数?而是在 toString 方法中采用数字原语?(见下面的例子)
其次,为什么下面列出的第二行代码不起作用(通过将 String 作为第一个参数)而第一行工作正常(通过将 long(或 int)作为第一个参数)。
两种方法都应分别以 String 和 Long 类型返回第一个参数中所述值的值,该值转换为第二个参数中指定的基数(在本例中为 8)。
String s = Long.toString(80,8)// takes a numeric primitive and it works fine.
Long l = Long.valueOf("80",8)// takes a string as first argument it does not compile,
//(as it was because in radix 8 cannot "read" the number 8
// and therefore it prompts an NumberFormatException.