Java generics name clash , has the same erasure

前端 未结 6 1603
[愿得一人]
[愿得一人] 2020-12-15 03:56

I have superclass Foo. And a class Bar extending it.

public class Bar extends Foo

Function in Foo:

protected void saveAll(C         


        
6条回答
  •  清歌不尽
    2020-12-15 04:09

    You just overriding methods with different Signatures.

    What will be good idea is to use PECS (Producer - Extends, Consumer - Super) rule described in Effective Java Second Edition by Joshua Bloch.

    according to this rule it should looks like this.

    In Foo class:

    public class Foo{
    
    protected void saveAll(Collection many){....}
    
    protected void getAll(Collection many){....}
    
    }
    

提交回复
热议问题