I am new to java. There is a method which return a value of type xxx.
public Cost getTotalCost() {
return getCost();
}
I want to convert the getCost() to type string. How do I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most universal way is:
This will handle nulls, or invoke the
.toString()method of the object.It would be best to implement the
.toString()method for yourCostclass.Note that it is considered poor practice to programmatically rely on the
toString()method – it should be for human eyes only and not be locked into a specific implementation.