Lambdas in Salesforce Apex
Asked Answered
M

2

9

Does Apex support the concept of lambdas?

Ultimately, I am trying to DRY up some really repetitive code in my tests, so I'd love to be able to pass functions around, something like this (C#-esq)

public static TestMethod void some_test_method(){
  Arrange( ()=>
    // some setup stuff
  );
  Act( ()=>
    // test action
  );
  System.assertEquals(...);
}
Macnamara answered 20/2, 2013 at 1:28 Comment(0)
C
17

Apex doesn't have lambdas. In fact, it doesn't even have anonymous classes. (That would have been your next question.) You're going to have to stick with declared classes. Apex does support Java-ish interfaces and abstract classes.

Calliper answered 20/2, 2013 at 1:58 Comment(0)
D
1

You can try R.apex(https://github.com/Click-to-Cloud/R.apex) for a functional stylish programming, although you still have to use declared classes.

Doty answered 5/5, 2018 at 5:0 Comment(1)
Welcome to Stack Overflow! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.Shoe

© 2022 - 2024 — McMap. All rights reserved.