The blog of Jafar Aliyev


Creation date:

Implicit typecasting

The compound operators (+=, -=, *=, and /=) do implicit typecastiong. If you compile the following code you will get a compilation error that 'possible loss of precision'.

byte a = 9;
a = a + 5;

Although the result wil fit to byte this operation produces int value. But when we use compound operator a += 5; compiler will be happy because compound operators make implicit typecast. Hence this shorthand is equal to
a = (byte) (a + 5);

Author: Jafar N.Aliyev (Jsoft)

Read also

Use instanceof carefully
Usage of 'instanceof' method in some situations will give you a compilation error

Wrapper objects

Static and instance initilization blocks


Java access and nonaccess modifiers
Look at this cheat sheet for Java access and nonaccess modifiers

Implicit typecasting

Protected details

Interface methods are always public

Static methods can not be overriden
Here I explain, why static methods can not be overriden

Java Tips

Variable hiding

Postfix operators

Tricky Polymorphism

Pattern Matching

Default values

String equality

© Copyright

All articles in this site are written by Jafar N.Aliyev. Reproducing of any article must be followed by the author name and link to the site of origin(this site). This site also keeps the same rules relative to the articles of other authors.