Why does android studio only let me set text (on a button or text view) by chars (and not strings?)

122 views Asked by At

Whether I try to change a textView or a button, why does Android Studio require that I pass only chars and not strings in the setText() method?

1

There are 1 answers

0
Carcigenicate On

Strings are automatically converted to CharSequences when necessary (or are CharSequences; can't remember. The point is, they're compatible):

public class Main {
    public static void testF(CharSequence seq) {
        System.out.println(seq);
    }

    public static void main(String[] args) {
        testF("Hello"); // Prints "Hello" 
    }
}

This would have been a good thing to try on your own or search for first.