Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does "" (double quote symbol) have methods?

How can a double quote ("") have a method even if you didn't actually declared it in a String. Like for example:

System.out.println("".length());

is "" an object already without declaring it on a String? or is it a keyword on Java that he knows it is already a string in the making?

like image 935
msagala25 Avatar asked Feb 04 '26 07:02

msagala25


1 Answers

JLS §3.10.5 explains what string literals are ("A string literal consists of zero or more characters enclosed in double quotes.") and also says:

A string literal is always of type String (§4.3.3).

like image 70
Seelenvirtuose Avatar answered Feb 05 '26 20:02

Seelenvirtuose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!