Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

My question is pretty much in the title. I would like to create an interface and then initialize it with a definition of the methods right then and there. Anyone familiar with Java would recognize this style of code.

If anyone wants use case, A Filter interface with a method filterOut. Another class has a method that takes a list of sobjects and an object of type Filter and returns only the items that match the conditions layed out in that Filter's filterOut method. Rather than create a pile of named inner or outter classes, it woubl be nice to just go:

filterList(listOfObjects, new Filter{
    Boolean filterOut(SObject obj){
        return obj.name == 'Bob';
    }
}

Can anyone tell me if this is possible?

share|improve this question
add comment

1 Answer 1

up vote 11 down vote accepted

Afraid it's not supported. Apex does have inner classes, up to one level deep, but there is no support for anonymous inner classes.

The closest you're going to be able to do is make private inner classes and use those in methods, which half defeats the point.

share|improve this answer
    
I figured, the documentation said nothing of the sort but I thought to ask anyway. Thanks. –  Bob Roberts Mar 29 at 14:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.