• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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.
 
His brain is the size of a cherry pit! About the size of this ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic