総称型とクラスの親子関係 » 履歴 » バージョン 1
sylow castle, 2019/03/20 18:19
| 1 | 1 | sylow castle | # 総称型とクラスの親子関係 |
|---|---|---|---|
| 2 | |||
| 3 | 以下はJavaのコード |
||
| 4 | |||
| 5 | ``` |
||
| 6 | public class GenelicType { |
||
| 7 | public static void main(String[] args) { |
||
| 8 | List<String> list1 = new ArrayList<String>(); |
||
| 9 | List<Object> list2 = new ArrayList<Object>(); |
||
| 10 | Collection<String> list3 = new ArrayList<String>(); |
||
| 11 | Collection<Object> list4 = new ArrayList<Object>(); |
||
| 12 | |||
| 13 | TypeOF(list1); |
||
| 14 | TypeOF(list2); |
||
| 15 | TypeOF(list3); |
||
| 16 | TypeOF(list4); |
||
| 17 | |||
| 18 | System.out.println(String.format("list1 ", list1 instanceof List)); |
||
| 19 | } |
||
| 20 | |||
| 21 | public static void TypeOF(Collection<Object> collection) { |
||
| 22 | } |
||
| 23 | } |
||
| 24 | ``` |
||
| 25 | |||
| 26 | |||
| 27 | NetBeansさんは"TypeOF(list1);"と"TypeOF(list3);"に対して以下のような警告を出してきた。 |
||
| 28 | |||
| 29 | > 不適合な型: List\<String\>をCollection\<Object\>に変換できません |
||
| 30 | > 不適合な型: Collection\<String\>をCollection\<Object\>に変換できません |