Is 5 * 5 literal or just an expression?

I know that, for example, '5' is a char literal, but is a 5 * 5 literal? This expression, however, has a fixed meaning.

+5
source share
4 answers

As described in the Java Language Specification §15.28 , this is a special case of an expression called a “compile-time constant expression”. This is not literal.

+12
source

I do not think you can call it literal. Perhaps some compilers will handle it the same way they deal with a literal, see Comment on which language you use.

+1
source

"Literal" is a grammatical term, not a semantic one. This is the main building block that denotes a constant value.

Although according to the specification 5 * 5 and 25 means exactly the same thing, grammatically the first of them is a binary expression containing two literals and an operator, and the second is just a literal.

+1
source

I'm not sure, but don't these terms work?

  • while you use a value to accurately determine the value of the variable "in the direct path" it should be called "literal",

    var num =5; var stringLabel = "someText"; etc.

  • while you are using a formula or recipe, it should be called an "expression",

    var result = 5*5; var res2 = a*x;

But of course, in result , which is also a constant si, it can also be literal in fact.

That's how it turned out, at least I ..

It's just about the terms, as well as in java, there are methods, "C languages" are functions, etc. - in the values ​​it is also one and the same, so it depends only on what you will endure in general: D

0
source

All Articles