r8mrag
Last Updated: February 25, 2016
·
2.625K
· jxcoder
Efa98106c67b35b3a69e63f350230c71

Java Tip #1. Stop to use "toString" method!

When you need to get string value of some object you should use String.valueOf method.
The String.valueOf method is null-safe and more clear way to get string value of the target object.

class SomeClass {
    @Override public String toString() {
        return "String value of SomeClass instance!"
    }
}

public class Main {
    public static void main(String[] args) {
        SomeClass someClassInstance = new SomeClass();

        System.out.println(String.valueOf(someClassInstance));
    }
}
Say Thanks
Respond

3 Responses
Add your response

9257
Default profile 4 normal

Well done!!! You awesome =)

over 1 year ago ·
9329
Default profile 4 normal

Nice tip! thanks...

over 1 year ago ·
9955
0 r4vdwb1wtfi0sl2wkvt wzrxko5a7 gwtjttwzlv7dl3knedyo53fvluycla2zy5arb1qt7kl ih

remember this

over 1 year ago ·
Awesome Job

E7334122 1780 11e8 9aaf caa9487f1cb0
DevOps Engineer
·
Negotiable, Sydney or Canberra pref
·
Full Time