3

Difference between between

  1. String s=new String('salesforce');
  2. String s='salesforce';

Why first statement is invalid in salesforce??

1 Answer 1

5

In Java (the language upon which Apex is based) there is a difference in terms of where that String gets stored in the String literal pool. Apex simply disallows the use of the constructor so that all strings are stored in a pool. This has a variety of implications in terms of memory storage and security, which is why (I suspect) Apex only allows the latter and not the former.

You must log in to answer this question.

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