Posted by:xinhangyang
Posted on:2007-08-18 23:42
如下一个公有方法:
public String toString(){
return String.format( "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f\n",
"employeeName",firstName,lastName,
"socialSecurityNumber",socialSecurityNumber,
"grossSales",grossSales,
"commissionRate",commissionRate);
}
此方法功能 : 返回一个包含本对象5个私有变量的字符串
其中 firstName(String)
lastName(String)
socialSecurityNumber(String)
grossSales(double)
commissionRate(double) 为私有实例变量
编译后提示 The method format(String, Object[]) in the type String is not
applicable for the arguments (String, String, String, String,
String, String, String, double, String, double)
是不是参数配制的问题呢?可这是摘自deitel编的<>
在JDK1.6文档中对String.format 是这样介绍的
format(Locale l, String format, Object... args)
Returns a formatted string using the specified locale, format string, and arguments.
format(String format, Object... args)
Returns a formatted string using the specified format string and arguments.
会不会是调试环境搭建的问题?我用的是jdk1.6.0_02 和 eclipse3.0 .