/** * Example of casing of primitive types * @author gtowell * Created: Jan 2021 */ public class Casting { /** * Do some casting. */ private void trial() { int x = 5; double y = 1.2; y = x; // implicit cast of int to double works x = y; // implicit case of double to int does not work, "Possible loss of precision" y = (double) x; x = (int) y; // you can always force. This will truncate 4.99999 -> 4 } public static void main(String[] args) { Casting casting = new Casting(); casting.trial(); } }