Problems with Using Generics in java-13.15 from the ground up (2)-implementing parameterized interfaces and overloading
This chapter discusses two relatively biased knowledge points: Implementing parameterized interfaces and overloading.
I think these two knowledge points are interesting.
1. Implement parameterized Interfaces
The following code cannot be compiled:
Package com. ray. ch13; interface Generator
{} Class MyGenerator implements Generator
{} Class MyGenerator2 extends MyGenerator implements Generator
{// Cannot be compiled, throwing an exception}
The main problem with the code above is that MyGenerator2 has repeatedly implemented the same interface twice, one is when inheriting MyGenerator, and the other is when implementing Generator.
2. Overload
Package com. ray. ch13; import java. util. ArrayList; public class Test {public void test (ArrayList list) {} public void test (ArrayListList ){}}
The above code is incorrect. For the reason of Type erasure, all generics in the ArrayList at the jvm level will be replaced Therefore, the above two methods do not implement overloading.
Summary: This chapter mainly shows two relatively biased knowledge points.
This chapter is here. Thank you.