在java.util.Arrays类中找不到静态方法asList(java.lang.String)

问题描述 投票:0回答:1
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Apache BSF: 2.4.0

我正在尝试在BeanShell中使用以下代码:

import java.util.Arrays;
import java.util.List;

// Set the mongodb query (must be a pipeline)
List query = Arrays.asList("");

并且我收到以下错误:

15:01:46,351 ERROR [BSFManager] Exception: 
java.security.PrivilegedActionException: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;  import j . . . '' : Typed variable declaration : Error in method invocation: Static method asList( java.lang.String ) not found in class'java.util.Arrays' : at Line: 20 : in file: inline evaluation of: ``import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;  import j . . . '' : Arrays .asList ( "" ) 
 BSF info: expression at line: 1 column: columnNo
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.bsf.BSFManager.eval(BSFManager.java:442)

任何想法?

java beanshell
1个回答
0
投票

您必须给它一个数组才能转换为列表。这是一个如何使用https://www.geeksforgeeks.org/arrays-aslist-method-in-java-with-examples/中的命令的示例:

    // Java program to demonstrate 
// asList() method for String value 

import java.util.*; 

public class GFG1 { 
    public static void main(String[] argv) 
        throws Exception 
    { 

        try { 

            // creating Arrays of String type 
            String a[] = new String[] { "A", "B", "C", "D" }; 

            // getting the list view of Array 
            List<String> list = Arrays.asList(a); 

            // printing the list 
            System.out.println("The list is: " + list); 
        } 

        catch (NullPointerException e) { 
            System.out.println("Exception thrown : " + e); 
        } 
    } 
}
© www.soinside.com 2019 - 2024. All rights reserved.