Till now my idea was static and new keyword are independent but when using testclasses I've found new concepts which are confusing See below class , We've to declare list as static to use it in static method but using static and initializing it with new keyword is confusing
I'm not finding any other mean besides using 'static keyword' , when using list inside methods meant for test classes
I 'm also finding I can 'add' static as well as non static accounts inside this static list. what does that mean? (see statements under 'try' block below)
public class staticConcetps { public static integer iStatic = 1; public static Account accStatic; public static list<Account> AccListstatic = new list<Account>(); // Not able to understand this, static as well as new keyworld used public integer iNonStatic; public Account accNonStatic; public static void Funcstatic() { try { // adding non static account account accobj = new Account(); accobj.name = 'shekhar Acc1'; AccListstatic.add(accObj); // adding static account AccStatic = new Account(); accStatic.name = 'Account Static insert1'; AccListstatic.add(accStatic); insert AccListstatic ; } catch(system.Exception d) { system.debug('ExceptionMessage=' + d.getMessage()); system.debug('ExceptionLineNumber=' + d.getLineNumber()); }
} }