Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

477
Views
Java switch statement (why is this illegal?)
        final int a=2;
        final int b;
        b=3;
        
        switch(num){
            case a : // Legal
            case b : //Illegal
        }

case a is Legal but case b is Illegal.

Can anyone explain why?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

switch statement requires constant expression case labels.

While b is a constant after the code executed (so the final works), it is not a constant expression in the meaning of JLS : https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.28

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!