Returning an array of an object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone tell me what I am doing wrong here? This will not compile
because of line 2, but if I replace with Service.ContactTO[] contacts = null;
it will through an exception on line 3.

Thanks

1Service.ContactTO cntTO = new Service.ContactTO();
2 Service.ContactTO[] contacts = new Service.ContactTO();
3 contacts[0] = createNewContact1();

4 private Service.ContactTO createNewContact1()
5 {

6 Service.ContactTO cnt = new Service.ContactTO();
7 cnt.firstName = "Neil";
8 cnt.lastName = "Armstrong";
9 cnt.prefix = "Mr.";
10 return cnt;
}
 
You are creating a instance of ContactTo to an array of that type which is
invalid. Let the 2nd line be:

Service.ContactTO[] contacts = {createNewContact1()};

Can someone tell me what I am doing wrong here? This will not compile
because of line 2, but if I replace with Service.ContactTO[] contacts =
null;
it will through an exception on line 3.

Thanks

1Service.ContactTO cntTO = new Service.ContactTO();
2 Service.ContactTO[] contacts = new Service.ContactTO();
3 contacts[0] = createNewContact1();

4 private Service.ContactTO createNewContact1()
5 {

6 Service.ContactTO cnt = new Service.ContactTO();
7 cnt.firstName = "Neil";
8 cnt.lastName = "Armstrong";
9 cnt.prefix = "Mr.";
10 return cnt;
}
 
Back
Top