例如我可以有这样的东西吗:
public static void SAMENAME (sameparameter n)
{
some code ;
}
public static String SAMENAME (sameparameter n)
{
similar code;
return someString ;
}
最佳答案
这是不允许的。
Java中的方法签名被认为是方法名和参数列表。返回类型不是方法签名的一部分。
Definition: Two of the components of a method declaration comprise the method signature—the method's name and the parameter types.
来源:http://java.sun.com/docs/books/tutorial/java/javaOO/methods.html
关于java - 我可以用另一个采用相同参数但具有不同返回类型的方法重载一个方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2526621/