我有以下问题:
当在方法调用中使用指针作为参数时,我得到"错误:标识符预期"错误.
这是我的代码:
class Data {
Person a = new Person("John");
Person b = new Person("Mary");
a.willHug(b); // Gets error: <identifier> at this line
}
class Person {
private String name;
private Person hugs;
Person(String n){
this.name = n;
}
public void willHug(Person p) {
hugs = p;
}
}
Run Code Online (Sandbox Code Playgroud)