Has any one seen the array []
placed after the method signature like this?
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));
}
prints
[a, b, c, d, e]
In the past, odd notations have been for "C" compatibility, but I wouldn't imagine someone writing this in C either.
Does anyone know why this is even allowed?
I am using Java 7 update 10, in case it matters.
This does the same thing in Java 6. http://ideone.com/91rZV1
BTW this doesn't compile, nor would I expect it to
public static <T> List mySplit(String s)<T> {
return Collections.emptyList();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…