내부 클래스의 변수를 수정해야합니다. 컴파일러에서 정적 변수를 선언해야한다고 말합니다.하지만이를 수정할 수는 없습니다. 코드는 다음과 같습니다.Java의 내부 클래스에서 변수에 액세스
public class Outter{
private boolean b;
public Outter(){
b = false;
new Inner(b);
}
}
public class Inner{
public Inner(boolean b){
b = true;
}
}
C에 "extern"과 같은 것이 있습니까? 또는 어떤 솔루션 그래서 나는 b 변수를 수정할 수 있습니까? 정적으로 설정하고 전체 Outter 클래스를 매개 변수로 전달하려고 시도했지만 동일한 문제가 계속 발생합니다.
편집 : 문제는 내가 뷰 2 클래스에서 변수 "보기"를 수정해야하는 방법이다
public class MainView{
private boolean view;
//JMenus,JMenuItems, JPanels.. declarations
private JFrame frame
MainView(){
view = true;
//initializations
create_listeners();
}
public void create_listeners(){
Menu.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event){
if(View){
new View2(frame);
View = false;
}
}
}
);
}
}
public class View2{
private JButton back = new JButton("Back");
public View2(JFrame frame){
//initialitzatons
create_listeners();
}
public void create_listeners(){
back.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event){
frame.remove(MainPanel);
View = true;// HERE, i want to modify the variable
}
}
);
}
}
자세한처럼 잘 코드입니다.
잘못된 표를 작성하여 죄송합니다. 신속하게 처리했으며 이해할 수있는 코드 변환이 필요했습니다.
비슷한 질문에 대한 회신을보십시오 : http://stackoverflow.com/questions/6830637/what-is-the-equivalent-keyword-for-extern-in-java – sglahn