Static member 'java.lang.String.join(java.lang.CharSequence, java.lang.CharSequence...)' accessed via instance reference
时间: 2023-09-28 19:05:44 浏览: 109
The error message "Static member 'java.lang.String.join(java.lang.CharSequence, java.lang.CharSequence...)' accessed via instance reference" occurs when you try to call the static method `join` on an instance of the `String` class instead of calling it on the class itself.
The `join` method is used to join a group of strings together with a delimiter. It takes two parameters: a delimiter and an array of strings. Here is an example of how to use it:
```
String[] words = {"hello", "world", "how", "are", "you"};
String joinedWords = String.join(" ", words);
System.out.println(joinedWords);
```
In this example, we create an array of strings called `words`, and then use the `join` method of the `String` class to join the strings together with a space delimiter.
If you see the error message "Static member 'java.lang.String.join(java.lang.CharSequence, java.lang.CharSequence...)' accessed via instance reference", it means that you are calling the `join` method on an instance of the `String` class, rather than on the class itself. To fix the error, make sure you call the method on the class, like this:
```
String[] words = {"hello", "world", "how", "are", "you"};
String joinedWords = String.join(" ", words);
System.out.println(joinedWords);
```
Note that in the corrected code, we are calling the `join` method on the `String` class itself, not on an instance of the `String` class.
阅读全文