Constructors

可以使用 new 运算符调用构造函数。除了位于 java.lang 包中的类型(IntegerFloatString 等)之外,应使用所有类型的完全限定类名。以下示例展示了如何使用`new` 运算符调用构造函数:

You can invoke constructors by using the new operator. You should use the fully qualified class name for all types except those located in the java.lang package (Integer, Float, String, and so on). The following example shows how to use the new operator to invoke constructors:

  • Java

  • Kotlin

Inventor einstein = p.parseExpression(
		"new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German')")
		.getValue(Inventor.class);

// create new Inventor instance within the add() method of List
p.parseExpression(
		"Members.add(new org.spring.samples.spel.inventor.Inventor(
			'Albert Einstein', 'German'))").getValue(societyContext);
val einstein = p.parseExpression(
		"new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German')")
		.getValue(Inventor::class.java)

// create new Inventor instance within the add() method of List
p.parseExpression(
		"Members.add(new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German'))")
		.getValue(societyContext)