E
E
Evgeniy Rybalko2020-04-15 18:56:20
Java
Evgeniy Rybalko, 2020-04-15 18:56:20

How are primitives cast in Java?

Good afternoon
In the tutorial I read that the default literal is int.

By default, Java assumes you are defining an int value with a numeric literal.

that is , here 5 - in fact it is int? Why does this compile? and this is not?
short i = 5;
byte a = (int)0L;

byte a = (long)0L;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question