Does Apigee supports Lambda Expression

Hi 

I used forEach loop to iterate an array with lambda expression in JAVA . It is not throwing any error nor any response in apigee.

 1.   jsonLoansResponse.forEach(index ->{
JSONObject json = (JSONObject) index;

.

.

.

2.for (Object index : jsonLoansResponse) {
JSONObject json = ((JSONObject) index);

.

.

 I tried with both the examples it is working in my local but not in Apigee with for loop it is working fine. Can you please help me in this .

Queries:

1. ForEach / For loop has good performance

2.Does Apigee supports Lambda Expression 

@dino Chiesa

0 1 84
1 REPLY 1

Yes, you can use lambda expressions in Java callouts that you write for Apigee. 

The forEach will have approximately the same performance as the for (Object foo : list) version. 

In my experience, when there is an exception in the lambda function, it can result in surprising behavior. 

You may need to wrap your logic, maybe within the lambda, in a try...catch. 

Also - I noticed your use of JSONObject in the code snips. One thing you may want to be aware of.  Many JSON libraries use Java reflection in order to do their work. Reflection is not permitted within a Java callout. The symptom will be: the Java callout will throw an exception. If your code does not handle the exception, the callout will just fail. 

Here is a repo that explains and illustrates the problem, and makes a suggestion for how to work around the restriction: https://github.com/DinoChiesa/Apigee-Java-Json-Parse