If you want to return all objects at once, from one method call, it is best to encapsulate all objects in a (possibly internal) class and return an instance of this class.
class Container {
public static class Container {
Type1 obj1;
Type2 obj2;
...
}
private Type1 obj1;
private Type2 obj2;
...
public Container getAllObjects() {
Container container = new Container();
container.obj1 = this.obj1;
...
return container;
}
}
(Technically, you can also return multiple objects in an array Object[], however, I do not recommend this because of the lack of type safety and open possibilities for creating order errors.)
, , - : -)
class Container {
private Type1 obj1;
private Type2 obj2;
...
public Type1 getObject1() {
return obj1;
}
public Type2 getObject2() {
return obj2;
}
...
}