Generic wildcards in variable declarations in Scala

前端 未结 1 964
无人及你
无人及你 2020-12-10 02:12

In Java I might do this:

class MyClass {
    private List list;

    public void setList(List l) { list = l; }
}
<         


        
相关标签:
1条回答
  • 2020-12-10 02:47

    The direct analog to

    import java.util.List;
    List<? extends MyInterface> list;
    

    is

    import java.util.List
    var list : List[_ <: MyInterface]  = _;
    

    Same deal with Buffer

    To answer a comment you made earler, in Java type parameters are always invariant, not covariant.

    0 讨论(0)
提交回复
热议问题