我有超级Foo.还有一个扩展它的类Bar.
public class Bar extends Foo
Run Code Online (Sandbox Code Playgroud)
Foo中的功能:
protected void saveAll(Collection<?> many)
Run Code Online (Sandbox Code Playgroud)
栏中的功能:
public void saveAll(Collection<MyClass> stuff) {
super.saveAll(stuff);
}
Run Code Online (Sandbox Code Playgroud)
得到错误:
Name clash: The method saveAll(Collection<MyClass>) of type Bar has the same erasure as saveAll(Collection<?>) of type Foo but does not override it.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我使用内部类的层次结构来表示应用程序中的一些数据,我遇到了一个我根本不理解的错误消息.我的代码可以归结为以下最小的例子:
public class A {
public class B extends A {}
public class C extends B {}
}
Run Code Online (Sandbox Code Playgroud)
Javac(当然我的IDE)无法使用以下错误消息编译代码:
A.java:3: cannot reference this before supertype constructor has been called
public class C extends B {}
^
1 error
Run Code Online (Sandbox Code Playgroud)
我没有写this任何地方.没有比上面提供的更多的代码,所以我假设javac生成了与内部类相关的东西.
我找到了另一种表示我的数据的方法,所以我只是对它为什么不编译的一个很好的解释感兴趣.
class Test{
public static void main(String s[]){
String s1="welcome",s2="come";
System.out.println(s1==("wel"+"come")); //prints : true
System.out.println(s1==("wel"+s2)); //prints : false
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么println方法都给出了不同的结果.请详细说明.