Java – returns two different values from the method

I have a method to parse the string record list into an object and return the object list So my method signature is like this

Public list < parsedobject > parse (string [] records);

But I also want to return other indicators, such as the number of string records that have not been successfully parsed Now I am confused about how to return this indicator One option is to create another wrapper class that contains a list of resolved records and members that store these metrics

But I often face this situation, so I will eventually create many wrapper classes

I'm not sure if I explained it well What are the suggestions here?

Solution

Unfortunately, Java does not support returning multiple values from functions You can create a wrapper class, just like you said Another option is to pass in an integer array or an "indicator" object or something similar and modify it in parse It might be better to have one or more instance variables (rather than method variables) to track any type of diagnostic information you need

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>