Advertisement
quantumech

Untitled

Oct 27th, 2020
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.36 KB | None | 0 0
  1. public static <T> void swap(T a, T b)
  2.     {
  3.         T temp = a;
  4.         a = b;
  5.         b = temp;
  6.     }
  7.  
  8.      public static void main(String []args){
  9.         Integer a = 1;
  10.         Integer b = 2;
  11.        
  12.         swap(a, b); // Integer is object, should swap if pass by reference.
  13.        
  14.         System.out.println(a);
  15.         System.out.println(b);
  16.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement