返回值类型是数组的操作(The return value type is an array operation)

/**

  • @author lg
  • @Description 对于数组的判断,除了反射,还可以这样子来进行操作
  • @date 2022/1/14 9:52
    */
    public class SwitchTest {
    public static void main(String[] args) {
    try {
    Object obj = getObj(“110”);
    if (obj.getClass().isArray()){
    System.out.println(“hello,这是一个数组 “);
    int length = Array.getLength(obj);
    if (length == 0) {
    throw new IllegalAccessException(“数组长度为0”);
    } else {
    for (int i = 0; i < length; i++) { Object o = Array.get(obj, i); // 输出每个参数的值即可 System.out.println(o); } } } } catch (IllegalAccessException e) { e.printStackTrace(); } } public static Object getObj(String code) throws IllegalAccessException { Object object; switch (code) { case "110":{ object = new String[]{"1", "2", "3"}; break; } case "111":{ object = new String[]{"3", "4", "5"}; break; } default: object = "hello,world"; throw new IllegalAccessException("参数不合理异常"); } return object; } }
————————

/**

  • @author lg
  • @Description in addition to reflection, the judgment of array can also be operated in this way
  • @date 2022/1/14 9:52
    */
    public class SwitchTest {
    public static void main(String[] args) {
    try {
    Object obj = getObj(“110”);
    if (obj.getClass().isArray()){
    System.out.println(“hello,这是一个数组 “);
    int length = Array.getLength(obj);
    if (length == 0) {
    throw new IllegalAccessException(“数组长度为0”);
    } else {
    for (int i = 0; i < length; i++) { Object o = Array.get(obj, i); // 输出每个参数的值即可 System.out.println(o); } } } } catch (IllegalAccessException e) { e.printStackTrace(); } } public static Object getObj(String code) throws IllegalAccessException { Object object; switch (code) { case "110":{ object = new String[]{"1", "2", "3"}; break; } case "111":{ object = new String[]{"3", "4", "5"}; break; } default: object = "hello,world"; throw new IllegalAccessException("参数不合理异常"); } return object; } }