Alternative way to swap Integer# Java - 爪哇娇娃
g*y
1 楼
变态吧。
find from deja.com
void swap( Object[] objects ) {
Integer temp = objects[0];
objects[0] = objects[1];
objects[1] = temp;
}
void testIt() {
Integer a = new Integer(1);
Integer b = new Integer(2);
System.out.println( "a = " + a + ", b = " + b );
Object[] integers = new Object[] { a, b };
swap(integers);
a = (Integer)integers[0];
b = (Integer)integers[1];
System.out.println( "a = " + a + ", b = " + b ); }
find from deja.com
void swap( Object[] objects ) {
Integer temp = objects[0];
objects[0] = objects[1];
objects[1] = temp;
}
void testIt() {
Integer a = new Integer(1);
Integer b = new Integer(2);
System.out.println( "a = " + a + ", b = " + b );
Object[] integers = new Object[] { a, b };
swap(integers);
a = (Integer)integers[0];
b = (Integer)integers[1];
System.out.println( "a = " + a + ", b = " + b ); }