Then, in the previous chapter, we discuss two more points of knowledge: implementing parameterized interfaces and overloading.
The main author think these two points of knowledge is more interesting.
1. Implementing parametric interfaces
Here is the code that cannot be compiled:
Package Com.ray.ch13;interface generator<t> {}class Mygenerator implements generator<mygenerator> {}class MyGenerator2 extends Mygenerator implements generator<mygenerator2> {//cannot compile, throw exception}
The main problem with the above code is that MyGenerator2 repeatedly implements the same interface two times, one time when inheriting mygenerator, once when generator is implemented.
2. Overloading
Package Com.ray.ch13;import Java.util.arraylist;public class Test<a, b> {public void Test (arraylist<a> list {}public void Test (arraylist<b> list) {}}
The above code is wrong, because of the type erasure, the ArrayList inside the JVM level will be replaced with <t>, so the above two methods do not implement overloading.
Summary: This chapter mainly shows two more biased knowledge points.
This chapter is here, thank you.
-----------------------------------
Directory
Understanding java-13.15 problems when using generics (2)-Implementing parameterized interfaces and overloads