I am looking at code with this form:
1 package com.stackoverflow.java.questions; 2 import java.util.ArrayList; 3 import java.util.List; 4 public class B extends A<B> { 5 6 private 7 <C extends A> 8 List<C> getList(Class<C> cls) { 9 10 List<C> res = new ArrayList<C>();
Yes, I know this is ugly, but I reduced it as much as I could.
My question is: how to correctly parameterize the use of A on lines 7, 14 and 15?
I am currently receiving warnings (A is a raw type. References to generic type A must be parameterized) from Eclipse for lines 7 and 14. I suspect that I will get one for line 15 as soon as I fix the other two, but I donβt sure. In any case, this is not currently parameterized and probably should be, but I don't know what the syntax should be.
Any thoughts on how to add the correct semantics and parameter syntax to get rid of these warnings?
Note. I'm not sure if it matters if A is recursive generic. I still get the same warnings if I just use the "abstract class A {}" instead of my current definition.
Honestly, if it were my own code, I would change everything to be much simpler. Unfortunately, this is part of the API, so I'm trying to change it as little as possible.
Thanks!
UPDATE:
I can address warnings, parameterizing them, as expected, but at the cost of an error. The thing is, how do I get the class <A <B β> from an abstract class?
Sort of,
Class & l, A & l, B β cls = A.class;
However, this causes a type mismatch error.
UPDATE, Part 2:
Turns out you just can't do this due to type erasure. See my other question here.