Problems with Using Generics in java-13.15 from the ground up (2)-implementing parameterized interfaces and overloading

Source: Internet
Author: User

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.

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.