当前位置: 代码迷 >> Lotus >> 在JAVA代理中可不可以自定义函数类型。解决思路
  详细解决方案

在JAVA代理中可不可以自定义函数类型。解决思路

热度:54   发布时间:2016-05-05 07:07:21.0
在JAVA代理中可不可以自定义函数类型。
private   DocumentCollection   getcollection   ()
{
try{
            Session   session   =   getSession();
            AgentContext   agentContext   =   session.getAgentContext();
         
            Database   db   =   agentContext.getCurrentDatabase();
         
            DocumentCollection   dc1   =   db.getAllDocuments();
return   dc1;
}
catch(Exception   e)   {
e.printStackTrace();
}

}


反正怎么试都不能通过编译。

------解决方案--------------------
如果程序在return之前就异常退出了,函数就有可能没有返回值
试试下面这个,不管是否有异常,都会返回值。
private DocumentCollection getcollection ()
{
DocumentCollection dc1 = null;
try{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

Database db = agentContext.getCurrentDatabase();

dc1 = db.getAllDocuments(); }
catch(Exception e) {
e.printStackTrace();
}
return dc1;


}

------解决方案--------------------
二楼的解答是正确的,函数肯定是错误的,你定义了返回类型DocumentCollection ,而在函数体结束前没有返回值,编译肯定会出错。
  相关解决方案