I have a class
class Configuration {
I also have another class
class Log { public static void d(String format, Object... d) {
The Log class works fine, I use it all the time. Now when I do this:
Configuration config = getConfiguration(); Log.d(config);
I get a compiler error The method d(String, Object...) in the type Log is not applicable for the arguments (Configuration)
. I can solve this:
Log.d("" + config); // solution 1 Log.d(config.toString()); // solution 2
My problem: how is this different? In the first solution, the compiler notices that it must concatenate two lines, and the second - the configuration. So, Configuration#toString()
is called, and everything is in order. In the event of a compiler error, the compiler sees that a string is required, but Configuration is provided. Basically the same problem.
- Need: String
- Provision: Configuration
How are these cases different and why is toString
not called?
source share