質問するログイン新規登録

質問編集履歴

4

誤っていた個所を削除

2020/10/06 10:47

投稿

water_coffee
water_coffee

スコア7

title CHANGED
File without changes
body CHANGED
@@ -29,26 +29,7 @@
29
29
  The method test(Class<? extends A<?>>) in the type main is not applicable for the arguments (Class<B>)Java(67108979)
30
30
  ```
31
31
 
32
- クラスBのジェネリクスを外すとコンパイルは通ります。
33
- ```B.java:Java
34
- //これで通る
35
- public class B extends A<T>{
36
- }
37
- ```
38
- また、メソッドの引数のワイルドカードを<? extend A>に変更することでも(警告は出るものの)コンパイルは通りました。
39
- ```main.java:Java
40
- public class main{
41
32
 
42
- public void test(Class<? extends A> c) {
43
-
44
- }
45
-
46
- public void main() {
47
- test(B.class);
48
- }
49
- }
50
- ```
51
-
52
33
  なぜこういう挙動になるのかがいまいち理解できません。
53
34
  どなたか教えていただけないでしょうか?
54
35
  Bクラスにジェネリクスがついていようがいまいが、BクラスはA<T>クラスのサブクラスだと思うのですが…。

3

エラー内容修正

2020/10/06 10:46

投稿

water_coffee
water_coffee

スコア7

title CHANGED
File without changes
body CHANGED
@@ -26,7 +26,7 @@
26
26
  ```
27
27
  (追記)コンパイルエラーの内容は以下です。
28
28
  ```Java
29
- The method test(Class<? extends test3<?>>) in the type test1 is not applicable for the arguments (Class<test2>)Java(67108979)
29
+ The method test(Class<? extends A<?>>) in the type main is not applicable for the arguments (Class<B>)Java(67108979)
30
30
  ```
31
31
 
32
32
  クラスBのジェネリクスを外すとコンパイルは通ります。

2

コンパイルエラーの内容を追記

2019/12/02 00:09

投稿

water_coffee
water_coffee

スコア7

title CHANGED
File without changes
body CHANGED
@@ -24,6 +24,11 @@
24
24
  }
25
25
  }
26
26
  ```
27
+ (追記)コンパイルエラーの内容は以下です。
28
+ ```Java
29
+ The method test(Class<? extends test3<?>>) in the type test1 is not applicable for the arguments (Class<test2>)Java(67108979)
30
+ ```
31
+
27
32
  クラスBのジェネリクスを外すとコンパイルは通ります。
28
33
  ```B.java:Java
29
34
  //これで通る

1

タグの追加

2019/12/01 23:37

投稿

water_coffee
water_coffee

スコア7

title CHANGED
File without changes
body CHANGED
File without changes