Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9270749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:26:50+00:00 2026-06-18T15:26:50+00:00

In java or in scala declaring a string within single quotes would throw the

  • 0

In java or in scala declaring a string within single quotes would throw the

‘error: unclosed character literal’

I was wondering if anybody can tell me the exact mechanics of how the string within the single quotes is type checked by the compiler and then the determination of the error is made. Also, why does the compiler say ‘

unclosed character literal

‘ instead of

“String instead of char”

as the error description?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:26:51+00:00Added an answer on June 18, 2026 at 3:26 pm

    This is usually done by a lexical analyser. As the wikipedia article says, that is usually done by a finite-state machine, which are very fast and easy to generate.

    As for why it displays “unclosed character literal” instead of “string instead of char” is because the way languages are usually parsed (a different step than lexical analysis) makes it much harder for compilers to realize what the programmer intended than for a person looking at it. The context used by the compiler is usually what is to the left and above the problematic part, instead of the whole context.

    So, looking to the left of the opening quote, it is impossible to tell whether the error is a missing single quote, or whether the programmer mixed single quotes with double quotes. This is compounded in Scala by the syntax for symbols, ('aSymbol), which prevents it using the very next character as a way to distinguish one from the other.

    So, in the end, the error message is picked to reflect what is the most likely error, and, for anyone coming from Java, C or C++, using single quotes around strings is just not an habit. For people coming from scripting languages such as Ruby, Perl or Python, that’s another story.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know that if java/scala has the string object that could
How would I express the following java code in scala? a = b =
When I execute following code in scala REPL console: java.util.Collections.max(new java.util.ArrayList[String]()) NoSuchMethodError exception is
I have an existing java/scala application using a global thread pool. I would like
I have java API which return this type: ArrayList[ArrayList[String]] = Foo.someJavaMethod() In scala program,
How can I use scala and java within Eclipse ? When I add the
Java's Foo.class as well Scala's classOf[Foo] literal class syntax return a reflective view about
I have an application where I would like to have mixed Java and Scala
I am trying to compile a Maven Java/Scala mixed project that has a Scala
Our company produces a number of Java / Scala libraries for use by our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.