如何返回类-输入方法 [英] How to return class - type in a method
本文介绍了如何返回类-输入方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我上课
public class Engine {
Double engineSize;
public Engine(){
this.engineSize = 1.0;
}
public Double getEngineSize() {
return engineSize;
}
}
我还有另一堂课:
public class ModelT {
public Engine getEngine() {
return null;
}}
现在,我想通过此测试:
Now I want to pass this test:
@Test
public void shouldHaveTheCorrectEngineSize(){
assertThat(modelT.getEngine().getEngineSize(), is(1.0));
}
我很难在方法中返回引擎类型,我尝试了几种方法,但是知识有限,因为我是Java的初学者.请您告诉我我该怎么做?以及我可以进一步阅读的概念的名称是什么.
I have the difficulty how can I return the Engine type in a method, I tried several ways but knowledge is limited because I am beginner to java.. Could you please tell me how could i do this? and what is the name of concept that i could further read on..
推荐答案
也许我不理解您的问题,但是您的测试永远不会返回ok,因为在您的ModelT方法getEngine中,您返回的是null..
Maybe i'm not understanding your question but your test never will return ok because in your ModelT method getEngine you are returning a null..
尝试以下代码:
public class ModelT {
public Engine getEngine() {
return new Engine();
}
}
这篇关于如何返回类-输入方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文