December 12, 2011

Expecting more Java goodness in Apex?

Apex Runtime Update for Developer Edition Orgs complies Apex code to Java byte code. This change is awesome from performance improvements standpoint, but shall we expect more Java into Apex also ?

Few of the following Java features would be a nice addition to Apex:

1. Diamond operator

Why declare same Type information on both LHS and RHS with Generics. For ex. here is a redundant declaration for creating a Map

Map<String, Set<Integer>> numbersByKey = new HashMap<String, Set<Integer>>();

With Java 7, the same could be done simply by only specifying type information on LHS, as shown below. This would be a really nice feature to have in Apex also.

Map<String, Set<Integer>> numbersByKey = new HashMap<>();

Posted the same as Idea :

2. Support for Switch Case statement

Community is demanding this a lot, for more than a year. Please promote this idea on IdeaExchange

Recently Java 7, also added support for Strings apart from other primitives to Switch case, that could be a huge ease for Apex programmers too.

3. Have Generics support in Apex Language

Generics are partially supported in Apex, you must be using them with Collections and Batch Apex. But you can’t declare your own classes to have similar support like

 * Generic version of the Box class.
 * @param <T> the type of value being boxed

public class Box<T> {

    private T t; // T stands for "Type"

    public void add(T t) {
        this.t = t;

    public T get() {
        return t;

For more details about Generics please check :

Again found an Idea posted for the same :


4. Support for Reflection

Reflection API in Java is the key to so many rich frameworks and open source good ness. Apex partially supports some of that via giving good describe information on Sobjects. If the same could be made available for apex classes, that would open many possibilities for richer APIs and frameworks on Apex.

For more details about reflection please check this WIKI article :

Again, idea already posted on App Exchange for the same :

Your views ?

Want to make Apex even more awesome, please post ideas and share your views ?