Understanding java-13.15 problems when using generics (2)-Implementing parameterized interfaces and overloads

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.