0

What does the second line in the following code represent?

long longNumber = Integer.MAX_VALUE;
int intNumber = (int) longNumber;

I've created a longNumber and assigned it MAX_VALUE. What does the second line mean? Thanks in advance.

Saki Osive
  • 1,437
  • 1
  • 10
  • 21
  • 1
    Does this answer your question? [Casting variables in Java](https://stackoverflow.com/questions/5289393/casting-variables-in-java) – maloomeister Nov 27 '20 at 12:45
  • It does but someone cannot know by looking and search for casting, so I think this question is valid. – Saki Osive Nov 27 '20 at 12:49

1 Answers1

1

Writing "(Generic Type) VariableName" mean that you are changing the type of "VariableName" this syntax is called "CASTING"

In this case you are converting a Long variable to an Int variable.

Casting is not always a secure method becouse if the LONG number is higher than Integer.maxvalue the number will NOT be converted in the correct way (becouse LONG type has more bits than normal INT)

Nicomane
  • 11
  • 4