Salesforce - 无效的构造函数名称错误

Chr*_*ten 2 constructor controller class salesforce apex-code

我正在构建一个控制器来显示Visualforce页面上自定义对象的数据.这是我的班级:

public class myController {

    Opportunity opp;
    list<Leg__c> legs;

    public Opportunity getOpp() {
        if(opp == null)
            opp = [select name, Primary_Contact__r.name, Primary_Contact__r.email, Primary_Contact__r.phone from Opportunity
                where id = :ApexPages.currentPage().getParameters().get('id')];
        return opp;
    }
    public getLegs() {
        legs = [select Departure__c, Arrival__c from Leg__c
                where Opportunity__c = :ApexPages.currentPage().getParameters().get('id')];
    }

}
Run Code Online (Sandbox Code Playgroud)

我无法编译!我一直在

错误:myController编译错误:无效的构造函数名称:第12行第12行的getLegs

我做错了什么,怎么能解决这个问题?

sup*_*ell 7

你有一个函数,public getLegs()因为它没有指定一个返回类型,它认为它是一个构造函数,但是名字有错,所以错误有点误导,实际的问题是getLegs()函数没有说明它的返回值类型是,它应该是e public List<Leg__c> getLegs()(你需要添加一个return legs)