From TipSmart's sample paper class MyClass { public static void main(String []args) { final int i = 100; byte b = i; System.out.println(b); } } Here is the answer from website => Will compile and print 100 How come that we don't need to explicitly cast from int to byte? Thank you for your clarification
Michael Burke
Ranch Hand
Joined: Jul 29, 2000
Posts: 103
posted
0
Because the int is final and so is a constant. The compiler can figure out the value at compile time and since 100 fits into a byte the compiler allows it. Anyone else want to clarify?
Vladimir Kositsky
Ranch Hand
Joined: Nov 03, 2000
Posts: 116
posted
0
My compiler issued approval It does not compile without final
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.