recently I have seen several codes whose method parameters contain array types, but when passing arguments, they are not written in array form, that is, they are not surrounded by curly braces, but can actually run. What is the reason for this? Thank you! The
code is as follows:
example 1:
@WebServlet(description = "a enter for wechat", urlPatterns = { "/aaa"},loadOnStartup=1)
example 2:
@WebServlet(description = "a enter for wechat", urlPatterns = "/aaa",loadOnStartup=1)
Webservlet comment source code:
/**
* @return array of URL patterns to which this Filter applies
*/
String[] urlPatterns() default {};
question 1:
after reading the source code, I think that the assignment of urlPatterns should be written according to example 1, but in fact, many people use the method of example 2, but shouldn"t the assignment of example 2 be of string type instead of string array? Doesn"t that make the parameter types mismatch? But in fact, I tested and found that both ways of writing can be used. Why is that?
question 2: what if urlPatterns has more than one url instead of one? Is it necessary to write {url1,url2} in curly braces as shown in example 1?
Thank you!