In a test code (in Java), the purpose of which was to convert a string to another string by intersecting the letters between uppercase and lowercase letters, I received the error a follow at compile time:
error: char can not be dereferenced
result = letter.toLowerCase ();
Following is the sample code:
public void solve(String text) {
int len = text.length();
StringBuffer buffer = new StringBuffer(len);
for(int i=0; i<len; i++){
char letter = text.charAt(i);
char result;
if (i % 2 == 0)
result = letter.toUpperCase(); //error: compile time
else
result = letter.toLowerCase(); //error: compile time
buffer.append(result);
}
System.out.println(buffer.toString());
}
solve("Teste");
// Resultado esperado:
// TeStE
Why does the error happen and what does it mean?