关于Object[]一直找不到原因的疑问?
记得好多次涉及到Object[]的代码都出现了这样的问题,然而百度了一下并不能解决,求个大神来指点迷津。。。。
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb);
formatter.format("%4$2s %3$2s %2$2s %1$2s","a", "b", "c", "d");
第三行的format红色下划线:The method format(Locale, String, Object[]) in the type Formatter is not applicable for the arguments (String, String, String, String, String)
代码的道理我能理解,但是不知道为什么会报错,代码写的应该没错吧, MyEclipse中的compiler也调为1.7,但是没用。基本上遇到了Object[]的代码全都有这个问题。
除非这样写 才不报错:
Object[] obj = {"a", "b", "c", "d"};
formatter.format("%4$2s %3$2s %2$2s %1$2s", obj);
但是这样写太笨重了,想问问第一种情况能不能改正过来。