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?

问题评论:

4  
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?
3  
What part of the error message don’t you understand? Your code makes no sense.
1  
multiple returning is not allowed in java, what do mean with return all objects
2  
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

原文地址:

https://stackoverflow.com/questions/47755477/java-for-loop-return-all-objects-in-the-array

Add a Comment