I have a method with an Object o
parameter.
In this method, I exactly know there is a String
in \"o\" which is not null. There is no need t
If you know the Object o is a String, I'd say just cast it to a String and enforce it that way. Calling toString() on an object that you know for sure is a String might just add confusion.
If Object o might be anything other than a String, you'll need to call toString().
Given that the reference type is an Object and all Objects have a toString() just call object.toString(). String.toString() just returns this.
I would use a cast. That validates your "knowledge" that it's a string. If for whatever reason you end up with a bug and someone passes in something other than a string, I think it would be better to throw an exception (which a cast will do) than continue to execute with flawed data.