What is the technical name of the syntactic feature “long foo = 12L;” style casting of harded-coded values in Java?

StackOverflow https://stackoverflow.com/questions/943350

  •  09-09-2019
  •  | 
  •  

Question

Today, I was trying to cast a hard-coded value into a short and S did not work. So, I went to search for it, but I realized that I do not even know what this feature of Java's syntax is called. Is there a name for it? If not, is there at least a list of all of the possible ways to cast hard-coded numeric values?

Epilouge

After getting the answer "Literals", I was able to answer my question about shorts. In case you are wondering, there is no short literal in Java. You just have to explicitly cast it as so: (short)12.

Was it helpful?

Solution

They are called literals.

From the Primitive Data Types page of The Java Tutorials:

A literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation.

There's a list of literals that can be used in the Primitive Data Types page under the Literals section.

Section 3.10: Literals of the Java Language Specification, Third Edition has a complete list as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top