大家.我有一个关于java中返回值的新手问题.这是我的代码.
@Override
public long addDrugTreatment(long id, String diagnosis, String drug,
float dosage) throws PatientNotFoundExn {
try {
Patient patient = patientDAO.getPatientByDbId(id);
long tid = patient.addDrugTreatment(diagnosis, drug, dosage);
Connection treatmentConn = treatmentConnFactory.createConnection();
Session session = treatmentConn.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(treatmentTopic);
TreatmentDto treatment = null;
ObjectMessage message = session.createObjectMessage();
message.setObject(treatment);
producer.send(message);
return tid;
} catch (PatientExn e) {
throw new PatientNotFoundExn(e.toString());
} catch (JMSException e) {
logger.severe("JMS Error: " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
Eclipse报告"此方法必须返回long类型的结果"错误.然而我确实在try块中返回了tid; eclipse建议在try/catch块之后添加一个返回值,这会破坏逻辑.你能告诉我这里有什么问题吗?谢谢.
为域实体使用接口的目的是什么?
在我们的项目中,我们使用域实体的接口。在接口内部,只有 getter 和 setter 方法,甚至没有任何域逻辑。
为这样的实体使用接口有用吗?这是好的做法吗?
谢谢。
每个人。我是 PHP 新手。我遇到这个问题DateTime:
$t1 = new DateTime();
$t1->setTime(9, 30);
$t2 = $t1;
$t2->add (new DateInterval('PT10M'));
echo $t1->format('H:i'); # outputs 9:40
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,通过改变 的值$t2,我也改变了 的值$t1,这不是我想要的。请您告诉我为什么会发生这种情况,以及如何避免这种情况。谢谢。
伊恩