I am doing a project in Java which has a lot of methods that require multiple return objects. For this I have to keep creating private classes which encapsulate the return objects. The objects make sense as a FontResult in my code will return the font name and the font size for example but constantly creating new objects for each return type I require feels wrong and somehow like I am trying to circumvent how Java should be written. Is this wrong or is it fine to do it like this? Should I be structuring my code in more of a tell-dont-ask approach?
An example is as follows:
String test = "hello";
StringResult result = getInformation(test);
int length = result.length;
private StringResult getInformation(String test) {
int length = test.length();
char firstChar = text.charAt(0);
}
private class StringResult {
int length;
char firstChar;
StringResult(int length, char firstChar) {
this.length = length;
this.firstChar = firstChar;
}
}