假设我有这样的代码
public void init(){
addMouseListener(this);
addMouseMotionListener(this);
}
Run Code Online (Sandbox Code Playgroud)
基于JAVA文档,
在方法或构造函数中,这指的是当前对象,即调用其方法或构造函数的对象......
基于代码,我可以得出结论,"this"指的init()是不调用addMouseListener()或不调用方法的对象addMouseMotionListener()
这是真的吗?
我还在学习Java集合框架及其工作原理....
据说我们不能分配涉及类型参数的大小,所以当我写下面的代码时
Stacks<card> stack = new Stacks[5]; // it causes a compiler warning
Run Code Online (Sandbox Code Playgroud)
有什么方法可以隐藏这个警告吗?
我写了以下代码:
class samplethis {
int a = 6;
int b = 7;
String c = "i am";
public void sample() {
System.out.println(this);
}
}
public class thiss {
public static void main(String[] args) {
samplethis cal = new samplethis();
cal.sample();// return samplethis@1718c21
}
}
Run Code Online (Sandbox Code Playgroud)
有谁知道它为什么会回来samplethis@1718c21?