You need to sign in to do that
Don't have an account?
philanthropy
apex basic syntax question
What is the difference between the following:
List<Movie__c> movieList {get; set;}
List<Movie__c> movieList = new List<Movie__c>{};
I'm assuming the second will need getter and setter defined? I'm trying to learn when the new keyword is necessary and when it isn't.
Thanks!
List<Movie__c> movieList {get; set;}
The above line is written if you want the movieList variable in the Apex class to be referred in the visual force page. You will do it by {!movieList}. If you don't use getter and setter you wont be able to use it in VF page.
List<Movie__c> movieList = new List<Movie__c>{};
The above line is creating a fresh list of Movie__c as the new keyword will define the list as a fresh copy.
So for the first one the new keyword is not required and the secord case this is required as you are creating a fresh copy of the list Movie__c.
Ok thanks for the reply, though I'm still a little confused.
Don't they both create a new list movieList?
Yes both of them will create new list.
Hi,
Adding to previous post.
change the following code
to
Otherwise it will not be worked.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Not true! The property version (below) does not create a new list. It creates a variable, which has the type of a list, but its value is null.
See this blog entry which compares properties to getters and setters.