1

I do not know of any special meanings for the hash character (#) in Java. Yet, I cannot create a variable with a name containing the hash character. Is there any reason? Is there actually a special meaning?

hyper-neutrino
  • 5,272
  • 2
  • 29
  • 50
  • The rules for classes apply for any identifier. – Sotirios Delimanolis Jun 01 '15 at 16:51
  • 2
    See https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8 – copeg Jun 01 '15 at 16:51
  • Why on Earth would you want to use `#` in a class name?? – vikingsteve Jun 01 '15 at 16:52
  • They didn't say that they wanted to use `#` to start a class, but rather was curious as to *why* it couldn't be used. That an identifier can't start with a non-letter doesn't answer the question. *Why* can't it start with a non-letter? Why did the language authors disallow it? Interesting answers would touch on language design, lexing and parsing. – Chris Scott Jun 01 '15 at 16:57
  • 2
    @16bytes Those would be too broad for Stack Overflow. The answer to why you can't is simply the language doesn't allow it. – Sotirios Delimanolis Jun 01 '15 at 17:02
  • I disagree that such an answer would be too broad or in-depth, but that's not worth debating. What about the second part of the question: is there a special meaning for the hash character? That's hard to search for, which is another reason why I thought it was a valid question. – Chris Scott Jun 01 '15 at 19:27
  • @vikingsteve To identify the class... Same reason you use any other character in a class name. If the OP finds that it would be easier to use a `#` then so be it. Hell, you could just not use any capital letters in class names. Why do you need them? Words in class names could be separated with underscores. So why would you ever want to use a capital letter? – Kröw Sep 18 '18 at 15:51

0 Answers0