function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Doug Beltowski XDoug Beltowski X 

Error when trying to implement toString method on a custom class

I'm trying to implement a toString method on a custom class I've created.  However whenever I try to save I get the error. "Method must use the override keyword: String toString()".  I'm not sure exactly what I'm doing wrong.  Below is my code.
 
public String toString()
{
	return csvCell;
}

csvCell is defined as a private String.
Best Answer chosen by Doug Beltowski X
Antonio ManenteAntonio Manente
I've never tried this before but I believe it may be possible using the 'override' keyword.

e.g.
 
public override String toString()
{
	return csvCell;
}

The only thing is that as far as I know, toString() is not a method on the String class. It basically calls the "String.valueOf()" method on the object your trying to coerce. Either way, I hope this helps!