Skip to content

Instantly share code, notes, and snippets.

@tksmaru
Created April 5, 2013 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tksmaru/5315709 to your computer and use it in GitHub Desktop.
Save tksmaru/5315709 to your computer and use it in GitHub Desktop.
引数が継承関係にあるオーバーロードメソッドの挙動確認
import java.util.*;
/**
* 引数が継承関係にあるオーバーロードメソッドの実験
*/
public class InterfaceTest {
/** Collection を要求する */
public static <T> void doSomething(Collection<T> collection) {
System.out.println("1");
}
/** Listを要求する */
public static <T> void doSomething(List<T> list) {
System.out.println("2");
}
public static void main(String [] args) {
List<String> test1 = new ArrayList<String>();
doSomething(test1); // 2
Collection<String> test2 = new ArrayList<String>();
doSomething(test2); // 1
Set<String> test3 = new HashSet<String>();
doSomething(test3); // 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment