Hello, Why will the code below compile, but if "final" is taken out it won't? What is the principle? Thanks so much, Emerald class Test { public static void main(String []args) { final int i = 100; byte b = i; System.out.println(b); } }
By making i final you are declaring to the compiler that it is a constant. Since the value of i can never change, and you can fit i's value of 100 into a byte, the compiler allows it. If i is not a constant (i.e., you remove "final"), the compiler complains. Art
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop