Java – unbounded wildcard passed to method
•
Java
@H_ 301_ 7@public class ColTest { static
T wildSub(ArrayList holder,T arg){ T t=holder.get(0); return t; } public static void main(String[] args) { ArrayList list=new ArrayList
(Arrays.asList(2L,3L,7L)); Long lng=1L; ColTest.wildSub(list,lng); } }
I'm really interested in why this fragment is legal, because the signature of wildsub only accepts t's ArrayList or derived from t, and the type is t's arg But Meaning – some specific types, unknown, and how does it satisfy the compiler? In all types After that doesn't mean
Solution
This is due to capture conversion Internally, the compiler converts the expression foo Type of To foo < x >, where x is a specific although unknown type
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码