Quantcast
Channel: Reza's Weblog
Viewing all articles
Browse latest Browse all 50

Target Typing in Java

$
0
0

Target typing is a language feature wherein the type of the variable in which a result is to be stored influences the type of the computation.

Java does not have it, and then the following expression does not return what we expect:

long MICRO_SECONDS_IN_DAY = 24 × 60 × 60 × 1000 × 1000;

To solve this, cast the right side to long:

long MICRO_SECONDS_IN_DAY = (long)24 × 60 × 60 × 1000 × 1000;

OR

long MICRO_SECONDS_IN_DAY = 24L × 60 × 60 × 1000 × 1000;

Viewing all articles
Browse latest Browse all 50

Trending Articles