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

构造函数

你可以使用 new 操作符来调用构造函数。除了位于 java.lang 包中的类型(如 IntegerFloatString 等)之外,其他所有类型都应使用完整的限定类名。以下示例展示了如何使用 new 操作符来调用构造函数:spring-doc.cadn.net.cn

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)