9

I came across the following snippet of code, and I wondered what purpose it may have, or if none, why Salesforce would even allow this to compile:

void BindData(Integer newPage) {
    Transient Integer counter = 0;
    Transient Integer min = 0;
    Transient Integer max = 0;
    // Calculate min/max, then loop using counter

Since the purpose of transient is to avoid serialization, it doesn't seem to make sense that you could mark variables within a function as transient, since you can't serialize functions (or, can you?).

I've already optimized this code away with something more efficient, I just wanted to know what possible use transient might have in this context.

2
  • Aesthetics? If the types had been something large in the heap I might have guessed something undocumented to do with garbage collection. More likely they used to be defined as instance variables on the class and were refactored into the method without dropping the keyword. Commented Jun 26, 2014 at 19:53
  • 1
    An off-hand comment from the author of MavensMate was that Salesforce were not willing to share the BNF for Apex. Maybe whoever wrote the compiler didn't get to see it either...
    – Keith C
    Commented Jun 26, 2014 at 20:36

1 Answer 1

2

I'd assume nothing, transient makes absolutely no sense for local variables. APEX has enough bizarre idiosyncrasies that I'd put my money on this just being an oversight rather than an intentional feature.

1
  • This would be my guess as well. Commented Jun 27, 2014 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .