【发布时间】:2012-02-06 04:35:38
【问题描述】:
我只是想知道为什么我使用以下代码得到“无法解析符号初始文本”。 isItA 是一个布尔值,用户根据他们将要粘贴到文本区域的文本类型(A 或 B)提前选择它。 initialText 有 2 个可能的字符串,输出的一个取决于布尔值 isItA。当我在 if/else 语句之外使用 initialText 时,我不明白为什么会弹出此错误;如果在“if/else”语句内,编译器应该能够解析外面的字符串吗?我目前在 IntelliJ 中使用 GWT。在这一点上,我仍然是java的菜鸟,因此非常感谢您对为什么会发生这种情况的基本解释:)提前致谢。代码的 sn-p 如下。
protected TextArea getNewTextArea() {
if ( newTextArea == null ) {
if (isItA){
final String initialText = "Please paste valid text A here, and then
press" + "the \"" + Labels.ADD_A_BUTTON_TEXT + "\" button.";
}else{
final String initialText = "Please paste valid text B here, and then press " + "the \"" + Labels.ADD_B_BUTTON_TEXT + "\" button.";
}
newTextArea = new TextArea();
newTextArea.setText( initialText );
newTextArea.addClickHandler( new ClickHandler() {
public void onClick( ClickEvent clickEvent ) {
// If the text is still the original text, then clear it.
if ( newTextArea.getText().equals( initialText ) ) {
newTextArea.setText( "" );
}
}
});
}
}
【问题讨论】:
-
如果是这样,那么您将无法在第二个声明中覆盖 initialText,因为它是最终声明。
标签: java string class gwt compiler-errors