I want to use lambda expressions inside a TextField expression like this:
Arrays.asList($F{field1}, $F{field2}, $F{field3}).stream().filter(i -> i != null).collect(java.util.stream.Collectors.joining(" / "))
Assuming this values for the fields:
$F{field1} = 1
$F{field2} = null
$F{field3} = 2
The expected result is of the TextField evaluation is:
1 / 2
Instead of I'm getting an error in the IDE:
Lambda expressions are allowed only at source level 1.8 or above
And this is the exception inside the IDE during the compile:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Lambda expressions are allowed only at source level 1.8 or above
value = "Contato: " + Arrays.asList(((java.lang.String)field_c_telefone.getValue()), ((java.lang.String)field_c_celular.getValue()), ((java.lang.String)field_c_fax.getValue()), ((java.lang.String)field_c_email.getValue())).stream().filter(i -> i != null).collect(java.util.stream.Collectors.joining(" / ")); //$JR_EXPR_ID=22$
<------------>
2. Lambda expressions are allowed only at source level 1.8 or above
value = "Contato: " + Arrays.asList(((java.lang.String)field_c_telefone.getOldValue()), ((java.lang.String)field_c_celular.getOldValue()), ((java.lang.String)field_c_fax.getOldValue()), ((java.lang.String)field_c_email.getOldValue())).stream().filter(i -> i != null).collect(java.util.stream.Collectors.joining(" / ")); //$JR_EXPR_ID=22$
<------------>
3. Lambda expressions are allowed only at source level 1.8 or above
value = "Contato: " + Arrays.asList(((java.lang.String)field_c_telefone.getValue()), ((java.lang.String)field_c_celular.getValue()), ((java.lang.String)field_c_fax.getValue()), ((java.lang.String)field_c_email.getValue())).stream().filter(i -> i != null).collect(java.util.stream.Collectors.joining(" / ")); //$JR_EXPR_ID=22$
<------------>
3 errors
.
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:206)
at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:294)
at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:146)
at net.sf.jasperreports.eclipse.builder.JasperReportsBuilder.compileJRXML(JasperReportsBuilder.java:220)
at com.jaspersoft.studio.editor.action.CompileAction.actionCompile(CompileAction.java:142)
at com.jaspersoft.studio.editor.action.CompileAction$1.run(CompileAction.java:93)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
I already changed my report project to use the JRE System 1.8, but the error continues.
How can I solve it? Does jasper compiler supports lambdas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…