Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <T> void swap(T a, T b)
- {
- T temp = a;
- a = b;
- b = temp;
- }
- public static void main(String []args){
- Integer a = 1;
- Integer b = 2;
- swap(a, b); // Integer is object, should swap if pass by reference.
- System.out.println(a);
- System.out.println(b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement