小编use*_*083的帖子

在Java中使用指针作为参数调用参数

我有以下问题:

当在方法调用中使用指针作为参数时,我得到"错误:标识符预期"错误.

这是我的代码:

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)

java parameters methods pointers identifier

1
推荐指数
1
解决办法
98
查看次数

标签 统计

identifier ×1

java ×1

methods ×1

parameters ×1

pointers ×1