Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Found some crazy apex syntax and I have no clue what it does.

public Account<List<String<Contact>>> whatIsWrongWithApex;

Is this a defect? Should this do something? Compiler not strict enough?

For the sake of the question, here is a simpler example:

public String<String> iThoughtThisShouldOnlyWorkForCollections;

Edit: Here is a full example where I instantiate an Account using this method and successfully insert it into the database:

public class ABug {
  public Account<List<String<Contact>>> whatIsWrongWithApex;

  public ABug() {
    whatIsWrongWithApex = new Account<List<String<Contact>>>();
    whatIsWrongWithApex.Name = 'Account Name';
    insert whatIsWrongWithApex;

Anonymous Apex:

new ABug();
share|improve this question
what happens when you run the code? even if it compiles what is the result? – jordan.baucke Dec 6 '12 at 21:26
It compiles. In the case of public Account<List<String<Contact>>> whatIsWrongWithApex; it works no different than public Account whatIsWrongWithApex; as far as I can tell. I am wondering if it serves any other purpose. – Phil Rymek Dec 6 '12 at 21:43
This is crazy, do you know who wrote the code? (and why) I wouldn't call it a bug, but a hole in the compiler checking as you said. If @RichUnger still visits this site he should be able to give an answer – Daniel Blackhall Dec 6 '12 at 21:48
Can you actually instantiate any of them with anything other than the top level type? I could only ever use new Account(); in the first example. – Daniel Ballinger Dec 6 '12 at 22:43
Based on this behavior, my guess is that type declarations for non-generic classes are simply ignored. Interesting, but not too severe. – jkraybill Dec 10 '12 at 1:21
up vote 9 down vote accepted

This 'strange' syntax is a result of native Java support for Generics.

We cannot leverage the power of generics in Apex just yet, but the platform itself most certainly does. This is likely being exposed here through the definition & inheritance of the sObject class.

Java Generic Types

share|improve this answer

Your Answer


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.