• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Get and Set methods for array of objects

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic