import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
public class MyTestDemo {
	public static String classify(Set s) {
		return "set";
	}
 
	public static String classify(List s) {
		return "list";
	}
 
	public static String classify(Collection s) {
		return "Unkonw Collection";
	}
 
	public static void main(String[] args) {
		Collection[] collections = { new HashSet(),
				new ArrayList(), new HashMap().values() };
		for (Collection c : collections) {
			System.out.println(classify(c));
 
		}
	}
}

这个应该不是你想要的结果

Unkonw Collection
Unkonw Collection
Unkonw Collection

然后试试

class Wine {
	String name() {
		return "wine";
	}
}
 
class SparkingWine extends Wine {
	String name() {
		return "sparking wine";
	}
}
 
class ChampagneWine extends Wine {
	String name() {
		return "champagne wine";
	}
}
 
public class MyTestDemo1 {
	public static void main(String[] args) {
		Wine[] wines = {new Wine(),new SparkingWine(),new ChampagneWine()};
		for(Wine wine : wines){
			System.out.println(wine.name());
		}
	}
}

结果是不一样的,所以重载不建议像第一种那样写,
改写成这样

public static String classify(Collection c) {
		return c instanceof Set ? "set" : c instanceof List ? "list"
				: "Unkonw Collections";
	}