Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assignments

 
Satya Baswa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. final int i=127;
2. byte b=i;

This piece of code works...

1. final int i;
2. i=127;
3. byte b=i;

This piece of code is not working.

What is the difference in the above two pieces of code?
 
Tarun Kumar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in first case since final object is assigned it's value at the declarion time hence compiler knows its values is <=127 ,thus allowing to compile.
in second case since final varible is not assigned at the declaration time,hence compiler can not be known about the later assigned value.
thus compiler is not sure wheather value is <=127,thus not allowing to compile.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic