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.

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
1  
what happens when you run the code? even if it compiles what is the result? –  jordan.baucke Dec 6 '12 at 21:26
1  
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
1  
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
show 3 more comments

1 Answer

up vote 6 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
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.