• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comments

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Can a string literal have comments in it? JLS 3.7, it is mentioned as follows:
-------------------------------------------------------------
The lexical grammar implies that comments do not occur within character literals (�3.10.4) or string literals (�3.10.5).
-------------------------------------------------------------
But the following program compiles and runs perfectly:
class Test
{
public static void main(String args[])
{
String str1="This is a /*comment*/ string literal";
String str2="This is a //comment string literal";
System.out.println(str1);
System.out.println(str2);
}
}
Am i missing something?
Thanks in advance.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what it says. You can't place comments inside a String literal because they are not treated as comments but as part of the String.
 
reply
    Bookmark Topic Watch Topic
  • New Topic