You need to sign in to do that
Don't have an account?

What is Instantiation
What happens during instantiation?
What are we trying to do by instantiating?
What is the difference
when I declare
List<Account> accntList = new List<Account>();
and when I declare
List<Account> accntList
Can someone please explain what happens with instantiation??
Many Thanks!
What are we trying to do by instantiating?
What is the difference
when I declare
List<Account> accntList = new List<Account>();
and when I declare
List<Account> accntList
Can someone please explain what happens with instantiation??
Many Thanks!
By using thisList<Account> accntList = new List<Account>(); you are creating an instance and at the same time instializing it with its default contructors
for more info refer this link
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_list.htm#apex_System_List_constructors
and when you declare List<Account> accntList; you just have created an instance of the list
I hope i have satisfied your query.
Regards
Nitesh
Thanks for your reply.
I have a slightly different understanding from the link you provided.
It says,
List<Account> accntList = new List<Account>(); ---- I'm creating an Instance.
List<account> accntList; ---- I'm just declaring a list variable.
I want to know the use of creating an instance.
Because sometimes I get 'attempt to de-reference null object' error if I try to use the list variable without instantiating it.
Many thanks!
see what i deduced is that whenever you are using a list it has elements stored using indexing so that when you query certain records records are fetched using indexes stored at heap location.That is why you have to create instance and that is why you get error when you don't do this.
Regards
Nitesh