cannot assign value to “final” variable in java

前端 未结 7 1178
臣服心动
臣服心动 2020-12-31 08:44
 private void pushButtonActionPerformed(java.awt.event.ActionEvent evt)
{
    final int c=0;
    final JDialog d=new JDialog();
    JLabel l=new JLabel(\"Enter the E         


        
相关标签:
7条回答
  • 2020-12-31 09:31

    final makes the "variable" a constant--you can't change it. As to why the compiler is giving you warnings after you delete the final keyword, we'd need to see the whole code...

    EDIT:

     but1.addActionListener(new ActionListener()
     {
         public void actionPerformed(ActionEvent e)
         {
             c=Integer.parseInt(f.getText());
             d.setVisible(false);
             d.dispose( );
         }
      });
    

    I believe this is the segment of code that causes the compiler to fire the warning. You can't use c in this class...

    0 讨论(0)
提交回复
热议问题