Using characters and String data in Gosu

To represent a single character in Gosu, use the primitive type char. To type a single character literal, surround it with single quotation marks, such as 'x'.

To represent a sequence of characters in Gosu, use the Java type java.lang.String. Because java.lang.String is always in scope, your code uses String unless a similarly named type is in scope and requires disambiguation. Create a String object by enclosing a string of characters in beginning and ending quotation marks. Example values for the String data type are "hello", "123456", and "" (the empty string). If you need to type a quotation mark character in a String literal, escape the quotation mark character by putting a backslash before it, such as "hello \"Bob\"".

Alternatively, you can use single quotation marks instead of double quotation marks. This style is useful if you want to type String literals that contain the double quotation mark character because you do not need to escape quotation mark characters:

var c = 'Hello "Bob"'

If you use single quotation marks and the literal has exactly one character, Gosu infers the type to be char instead of String.