Java Overloads Encounter generics

Source: Internet
Author: User

Asked an interesting question today, we all know the concept of overloading: A class that defines a method with the same name, the parameter table is different (the parameter type, or the parameter number is not the same);

But what if this is the two method below?

public static int fn (list<integer> index) {      return 1;   }   public static String  fn (list<string> str) {         return "str";   }  

The same name of the two methods, the parameter table used in the collection, the parameter list of the generic type is not the same, then in the end this can be compiled through it?

Repeated verification, the following conclusions are drawn

Using the Sun JDK's javac to compile will pass, while other compilers may refuse to compile this code

Java Overloads Encounter generics

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.