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

构造 函数

您可以使用new算子。您应该完全使用 限定类名称,适用于所有类型的类型,但位于java.lang包 (Integer,Float,String等)。以下示例演示如何使用newoperator 调用构造函数: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)