java:new
Creates a Java object instance for use in java:call to invoke non-static methods.
Information noteImportant:
- You cannot assign the result of java:new to a variable. Use it directly in java:call.
- You cannot use java:new alone. java:new is only used as the first argument of a Java function call. For more information, see Calling Java functions in expressions.
Arguments
- Class name (string).
- Arguments of the constructor (any type).
Examples
Creating an object and calling a method:
java:call(java:new("java.util.Random", 536815L), "nextInt", 100)This example creates a Random object with a seed and calls its nextInt method.
Creating an object with chained calls:
java:call(java:call(java:new("java.text.SimpleDateFormat", "yyyy-MM-dd"), "parse", "2018-10-15"), "getDate")This example creates a SimpleDateFormat object, parses a date string, and retrieves the date.