• Post Reply Bookmark Topic Watch Topic
  • New Topic

unclosed character literal  RSS feed

 
ye shi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have defined a variable of type char, and initialized with '', like this char rvalue = '';
But NetBeans said that it's not right, and give the following comments.

empty character literal
unclosed character literal

I posted the code.

public final synchronized char getChar(){
char rvalue = '';
try{
rvalue = (char) in.read();
in.readLine();
} catch(IOException e){

}

return rvalue;
}
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A char always contains a single character. There's no such thing as an "empty character". So, char rvalue = ''; doesn't work. You must put exactly one character between the quotes.
 
ye shi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:A char always contains a single character. There's no such thing as an "empty character". So, char rvalue = ''; doesn't work. You must put exactly one character between the quotes.

Thank you, Got it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!