4.12 method overload

xiaoxiao2021-03-06  59

Method Signature refers to the type of method name (with return type), the number of parameters, and parameters (consistency in order of parameters). When the Java compiler encounters a call to the same method name, it is determined which method of the call according to the type of parameter variable expression, which is called signature matching. This characteristic that can be defined by the same name is called method overloading. If the compiler does not find the corresponding method for the input parameter type, the expansion type conversion is performed, followed by continuing to match. Sometimes, it will cause compilation errors and ambiguous. If some expanded basic type conversion does not generate an erliness, the conversion process is nearest. AmbiguousoverLoad.java (has an unsurmous error, can't compile)

//Nmbiguousoverload.java: Won't compileclass AmbiguousoverLoad {public static void main (string [] args) {INT i = 1, j = 2; system.out.println (Ambig (i, j));} static boolean Ambig (float x, int y) {RETURN x

Unambiguousoverload.java

// UnambiguousOverload.java: no ambiguity hereclass UnambiguousOverload {public static void main (String [] args) {int i = 1, j = 2; System.out.println (unAmbig (i, j));} static boolean unAmbig ( FLOAT X, FLOAT Y) {RETURN X

转载请注明原文地址:https://www.9cbs.com/read-82231.html

New Post(0)