Mega Code Archive

 
Categories / Java Tutorial / Class Definition
 

Using final with method arguments

class A {   public void spin() {   } } class B {   void with(final A g) {     // g = new A(); // Illegal -- g is final   }   void without(A g) {     g = new A(); // OK -- g not final     g.spin();   }   int g(final int i) {     return i + 1;   } } public class MainClass {   public static void main(String[] args) {     B bf = new B();     bf.without(null);     bf.with(null);   } }