为什么@RequestMapping注释在Java中接受String参数,但在Scala中不接受? [英] Why does @RequestMapping annotation accept String parameter in java but not in scala?
问题描述
阅读@RequestMapping文档: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMapping.html
Reading the @RequestMapping documentation : http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/bind/annotation/RequestMapping.html
它接受String数组参数作为其路径映射.
It accepts a String array parameter for its path mapping.
所以这可以在java中使用:
So this works using java :
@RequestMapping("MYVIEW")
但是在scala中,我需要使用:
but in scala I need to use :
@RequestMapping(Array("MYVIEW"))
scala版本很有意义,因为注释需要一个String数组.但是,为什么上面的代码在Java中起作用,它不应该给出编译时错误吗?
The scala version makes sense as the annotation expects a String array. But why does above work in java, should it not give a compile time error ?
在"ArrayChecker"类(我写来说明这一点的类)下面导致了Java编译时错误:
Below class 'ArrayChecker' (a class I wrote to illustrate this point) causes a java compile time error :
ArrayChecker类型的方法acceptArrayParam(String [])不是 适用于参数(字符串)
The method acceptArrayParam(String[]) in the type ArrayChecker is not applicable for the arguments (String)
public class ArrayChecker {
public static void main(String args[]){
String[] strArray;
acceptArrayParam("test");
}
private static void acceptArrayParam(String[] param){
}
}
应该不是由@RequestMapping("MYVIEW")引起类似的错误吗?
Should a similar error not be caused by @RequestMapping("MYVIEW") ?