5

From documentation:

public String()

Initializes a newly created String object so that it represents an empty character sequence. Note that use of this constructor is unnecessary since Strings are immutable.

Did it have any use in previous Java versions?

Community
  • 1
  • 1
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • `String(String original)` has a similar note – tkausl Oct 30 '17 at 07:44
  • Similarly `String.copyValueOf(char[] data)` is documented as "Equivalent to `String.valueOf(data)`. It seems a pre-1.0 early version of Java didn't have immutable strings. – Klitos Kyriacou Oct 30 '17 at 07:52
  • 2
    No. It's a misconception from the early days of Java. But Java has always tried to stay backwards compatible, so these constructors are left there. – JB Nizet Oct 30 '17 at 07:53
  • 1
    @tkausl The difference is that `original != new String(original)`. – daniu Oct 30 '17 at 07:57
  • It could be historical, but it could just be another of those little idiosyncrasies with which Java abounds, like having a NullPointerException without having pointers. – Kevin Boone Oct 30 '17 at 08:05
  • `String(String)` did have some use pre-Java7 and the note says "unless ..." unlike this one. – Alexey Romanov Oct 30 '17 at 09:54

0 Answers0