Java generics name clash , has the same erasure

前端 未结 6 1576
[愿得一人]
[愿得一人] 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:31

    At runtime, the parameter types are replaced by Object. So saveAll(Collection) and saveAll(Collection) are transformed to saveAll(Collection). This is a name clash. Look here for details.

    You could do this :

    public class Foo {
        protected void saveAll(Collection many) {
            // do stuff
        }
    }
    
    public class Bar extends Foo {
    }
    

提交回复
热议问题