6

This might be a duplicate question but I couldn't find any answers. According to the documentation:

In Apex, you can have static methods, variables, and initialization code. However, Apex classes can’t be static.

I'm wondering why is that? My guess it has something to do with the Apex compiler, when sending uncompiled code to the server and it cannot access static classes ?

Hopefully someone might have an answer based on evidence.

1 Answer 1

6

Taking Java as an example, the static keyword can only be applied to a nested class. There it is used to distinguish between nested classes that can automatically reference the fields of the outer class (no static keyword) and nested classes that cannot automatically reference the fields of the outer class (static keyword).

In Apex, there is no variation possible: all nested classed behave like Java static nested classes. So the keyword is redundant when applied to classes in Apex and so not available.

0

You must log in to answer this question.

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