2015-01-07 30 views

回答

4

声明在同一个类中,它们是覆盖等效的,并且会导致编译错误。

Java Language Specification

It is a compile-time error to declare two methods with override-equivalent signatures in a class.

其中

Two method signatures m1 and m2 are override-equivalent iff either m1 is a subsignature of m2 or m2 is a subsignature of m1.

The signature of a method m1 is a subsignature of the signature of a method m2 if either:

  • m2 has the same signature as m1, or
  • the signature of m1 is the same as the erasure (§4.6) of the signature of m2.

加粗的情况下,这里的问题。

Class<?>的删除是Class

Is there any difference between void f(Class c) and void f(Class c) in Java?

从呼叫者的角度来看,没有。在该方法的主体中,是的。在第一种情况下,该参数具有raw typeClass。在第二种情况下,该参数具有参数化类型Class<?>

0

其实?是一个可以与参数化类/接口一起使用的通配符。例如,Collection<Object>是一个通用集合,其中包含Object类型的项目,而Collection<?>是所有类型集合的超类型。

相关问题