Skip to main content Skip to complementary content

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

  1. Class name (string).
  2. 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.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!