Java For-Loop-Return all Objects in the array


I have to program a method called public Gobject [] getGos(),which returns all given Gobjects in the array.

This is my code:

public Gobjects[] getsGos(){
    for (int i = 0; i < geo.length; i++) {
        Gobjects go = geo[i];
    return go;

Eclipse error said, that it cannot convert from Gobjects to Gobjects[].

I’ve tried casting, but that is also wrong.

What am I doing wrong?


What do you want to achieve with that loop? And what is geo? If that already is the array, then again, what’s the purpose of the loop?
What part of the error message don’t you understand? Your code makes no sense.
multiple returning is not allowed in java, what do mean with return all objects
per method you can only return 1 object. if you want to return more objects, you pack them in an array or a list or whatever
I have to return all objects in the array.
– Prodigy
1 hour ago


Add a Comment