我们知道每个类都从Object扩展,这意味着我们可以在任何类中使用所有Object的方法.我的问题如下:
interface B{
}
public class A implements B{
public static void main(String[] args){
B i = new A();
i.display();//we can't do this : because the interface B doesn't define such a method
System.out.println(i.toString());// we can do this although the interface doesn't extend from Object
}
public void display(){
}
}
Run Code Online (Sandbox Code Playgroud)
所以我认为问题很明显,为什么我可以调用toString方法虽然接口B不能从Object扩展?
我对一个小问题感到困惑,请参阅以下内容:
Double j = new Double(5); // No problem.
double j =5;//
//But
//Here the problem:
Double j = 5;
Long k =5;
Float g = 5.0;
Run Code Online (Sandbox Code Playgroud)
我知道解决方案,但我想理解为什么在某些情况下,演员是隐式完成而在其他情况下不是.