有没有人看过这样在方法签名后面放置的数组[]
?
public static String mySplit(String s)[] {
return s.split(",");
}
public static void main(String... args) {
String[] words = mySplit("a,b,c,d,e");
System.out.println(Arrays.toString(words));
}
打印
[a, b, c, d, e]
过去,一些奇怪的符号可能是为了与"C"兼容,但我也不想象有人会用C语言编写这个。
有人知道为什么允许这样做吗?
我正在使用Java 7更新10,如果有影响请告诉我。
在Java 6中也可以实现相同的功能。http://ideone.com/91rZV1
顺便说一句,这段代码没有编译通过,我也不指望它能编译通过。
public static <T> List mySplit(String s)<T> {
return Collections.emptyList();
}
toString
方法又拥有static toString(String)
方法没有问题。但是,你是正确的 - 我没有注意到这个调用或者觉得方法名有问题。 - John Dvorak