Java Generics Puzzler, extending a class and using wildcards

前端 未结 6 1795
不知归路
不知归路 2021-01-31 02:02

I\'ve been beating my head against this one for awhile and thought that maybe some fresh eyes will see the issue; thanks for your time.

import java.util.*;

clas         


        
6条回答
  •  伪装坚强ぢ
    2021-01-31 02:24

    Replacing the definition of TbinList with

    class TbinList extends ArrayList> {}
    

    and defining test2 with

    TbinList test2 = new TbinList<>();
    

    instead would solve the issue.

    With your definition you're ending up with an ArrayList> where T is any fixed class extending Base.

提交回复
热议问题