char不能在java中解除引用?

时间:2014-07-15 02:21:23

标签: java

static char guessLetter (String lettersGuessed)
{
  Scanner keyboard = new Scanner (System.in);
  System.out.println ("Guess a letter: ");
  char letterGuessed = keyboard.next().charAt(0);

  if (letterGuessed.isLetter())
  {
    return letterGuessed;
  }
  else 
  {
    System.out.println ("That is not a letter. Please try typing a letter again.");

我如何解决这个问题,它给我一个错误“char无法解除引用”

我不确定这意味着什么。

感谢。

1 个答案:

答案 0 :(得分:0)

char是原始类型,因此您无法在其上调用方法。此外,Character.isLetter(char)采用char参数,所以我认为你想要这样的东西

char letterGuessed = keyboard.next().charAt(0);
if (Character.isLetter(letterGuessed)) { // <-- the if test.
  return letterGuessed;
}