Why is it that Java requires the char variable to enclose anything inside of it with single quotes rather than double? An example of this:
char s = 's'; //This will not break
vs:
char s = "s"; //This will break
I understand that double quotes are primarily for strings but is there a specific reason as to why chars were built to only use single quotes and to break when a double quote is entered?
I have tried to do some research but the only thing that was relevant was another SO Question, which refers to the difference between single and double quotes, not the reasoning behind the syntactical development of the char.
Because char and String are two different types, and how else is Java supposed to know whether you want a character or string of length 1?
For example, given the methods:
public void foo(String s) { }
public void foo(char c) { }
And the call
foo("a");
If characters could be made with double quotes, how would Java know which method to call?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With