12

I'm trying to use the char method isLetter(), which is supposed to return boolean value corresponding to whether the character is a letter. But when I call the method, I get an error stating that "char cannot be dereferenced." I don't know what it means to dereference a char or how to fix the error. the statement in question is:

if (ch.isLetter()) 
{
....
....
}

Any help? What does it mean to dereference a char and how do I avoid doing so?

4

4 に答える 4

26

char 型はオブジェクトではなくプリミティブであるため、逆参照できません。

逆参照は、参照によって参照される値にアクセスするプロセスです。char はすでに値 (参照ではない) であるため、逆参照することはできません。

使用Characterクラス:

if(Character.isLetter(c)) {
于 2011-04-03T02:09:24.940 に答える
2

Acharにはメソッドがありません。これは Javaプリミティブです。Characterラッパー クラスを探しています。

使用法は次のとおりです。

if(Character.isLetter(ch)) { //... }
于 2011-04-03T02:09:50.880 に答える
1

chとして宣言されていると思いcharます。はプリミティブ データ型であり、オブジェクトではないためchar、メソッドを呼び出すことはできません。を使用する必要がありますCharacter.isLetter(ch)

于 2011-04-03T02:09:35.190 に答える
-1

少し冗長/醜いように見える場合Character.isLetter(ch)は、静的インポートを使用できます。

import static java.lang.Character.*;


if(isLetter(ch)) {

} else if(isDigit(ch)) {

} 
于 2011-04-03T07:08:35.337 に答える