Answer the question
In order to leave comments, you need to log in
Automatic conversion and explicit type conversion in JAVA?
Please tell us in plain language about type conversion.
Answer the question
In order to leave comments, you need to log in
Explicit is when you convert a variable of one type to another in brackets (or through method calls). At the same time, it is not a fact that this transformation will take place and will take place correctly.
An automaton is when a type that is "larger" is involved in operations with "smaller" types and a conversion is needed. Java itself will be able to convert, since the data is not lost.
Example:
int a = 70000;
short b = 10;
int c = a + b; // Тут b автоматом преобразуется к типу int, так как компилятор знает,
// что данные из него не потеряются при преобразовании.
short d = (short) (a + b);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question