Java - final variables

前端 未结 7 1246
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-16 01:43

I know that once a final variable has a value assigned to it, it cannot be changed. However I just have a couple of questions regarding this:

  • When I have a

7条回答
  •  無奈伤痛
    2020-12-16 02:18

    A better nice codding way :

    public class FinalVarTester 
    {    
        static final JButton button; 
        public FinalVarTester()
        {    
            JFrame frame = new JFrame();
            Container container = frame.getContentPane();
            container.setLayout(new BorderLayout());
            container.add(button, BorderLayout.SOUTH);
            button = new JButton("OK");
        }
        public static void main(String[] args)    
        {
            FinalVarTester vTester = new FinalVarTester();    
        }
    }
    

提交回复
热议问题