【发布时间】:2013-12-01 09:22:05
【问题描述】:
构造函数接受一个字符串并将其存储在局部变量
modifier中。然后我想通过getModifer()方法返回modifier。但是该方法无法返回从构造函数传入的String。请帮我找出问题所在。谢谢!
private String modifer;
public UMLAccessModifer(String input)
{
/**
* Takes in the type of access modifier.
*/
this.modifer = input;
if(input.toLowerCase().contains("public")){
this.modifer = "public";
}
else if(input.toLowerCase().contains("private")){
this.modifer = "private";
}
else if(input.toLowerCase().contains("protected")){
this.modifer = "protected";
}
else {
this.modifer = "private";
}
}
public String getModifer() {
/**
* Returns the string of Modifier.
*/
return modifer;
【问题讨论】:
-
更精确地处理您遇到的错误。一个输入/输出的小例子会很有用。
-
错误是什么,您的输入是什么??
-
input你用了什么,你得到了什么,你期待什么? -
问题似乎不是来自您的代码。检查您在构造对象时是否有效地传递了一个字符串。
-
我希望得到公共字符串。输入是来自 GUI 的用户输入,但它没有返回任何内容。控制台面板显示空指针异常的错误。
标签: java string oop get return