对于最新的稳定版本,请使用 Spring Framework 7.0.6!spring-doc.cadn.net.cn

构造函数

可以通过使用new操作符来调用构造函数。对于所有类型,您都应该使用完全限定的类名,除非它们位于java.lang包中(如StringMathSystem等)。 可变参数也受到支持。spring-doc.cadn.net.cn

以下示例展示了如何使用new操作符来调用构造函数。spring-doc.cadn.net.cn

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

// create new Inventor instance within the add() method of List
parser.parseExpression(
	"Members.add(new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German'))")
		.getValue(societyContext);
val einstein = parser.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
parser.parseExpression(
	"Members.add(new org.spring.samples.spel.inventor.Inventor('Albert Einstein', 'German'))")
		.getValue(societyContext)