File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Get and Set methods for array of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get and Set methods for array of objects" Watch "Get and Set methods for array of objects" New topic
Author

Get and Set methods for array of objects

Kd Martin
Ranch Hand

Joined: Nov 28, 2011
Posts: 58
How do you return an entire array from a "get" method? For instance, I'm trying to return an array of Instructor objects. I keep getting this error:

Course.java:77: illegal start of expression
this.Instructor[] = Instructor;

This is my code:


Also, how do you use a set method for an array? I'm getting an error in my Student class that says:
./Course.java:77: cannot find symbol
symbol : variable Instructor
location: class Course
this.Instructor[] = Instructor;
^
./Course.java:77: cannot find symbol
symbol : variable Instructor
location: class Course
this.Instructor[] = Instructor;
^

Thanks!
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3070
    
  33

There is nothing special that you got to do with the arrays, they are just another object and you use the setters the way you use for other objects, for example:


So in your Course class you have declared instructor of type Instructor and not an array. But your getters/setters are trying to deal with the Instructor array.

If at all you want to dynamically add the Instructor into a collection- you might want to consider some implementation of List.


Mohamed Sanaulla | My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get and Set methods for array of objects