Java Question strings in switch are not supported in -source 1.5

Discussion in 'Libraries developers questions' started by MarcoRome, Mar 13, 2015.

  1. MarcoRome

    MarcoRome Expert Licensed User

    I have this code:

    Code:
    /*
                Ogni mese è associato ad un carattere
            */
        
    public String calcolaMese() {
            
    switch (mese) {
                
    case "Gennaio":
                    mese = 
    "A";
                    break;
                
    case "Febbraio":
                    mese = 
    "B";
                    break;
                
    case "Marzo":
                    mese = 
    "C";
                    break;
                
    case "Aprile":
                    mese = 
    "D";
                    break;
                
    case "Maggio":
                    mese = 
    "E;";
                    break;
                
    case "Giugno":
                    mese = 
    "H";
                    break;
                
    case "Luglio":
                    mese = 
    "L";
                    break;
                
    case "Agosto":
                    mese = 
    "M";
                    break;
                
    case "Settembre":
                    mese = 
    "P";
                    break;
                
    case "Ottobre":
                    mese = 
    "R";
                    break;
                
    case "Novembre":
                    mese = 
    "S";
                    break;
                
    case "Dicembre":
                    mese = 
    "T";
                    break;
                            /*
                                Non arriverà mai a svolgere il Default
                            */
                default:
                    throw new IllegalArgumentException();
            
    }
            return mese;
        }
    when i compile with SLC i have this error:

    Code:
    javac 1.8.0_05
    C:\Users\smamici\Desktop\SimpleLibraryCompiler\CodiceFiscale\src\com\codicefiscale\CodiceFiscale.java:
    211: error: strings in switch are not supported in -source 1.5
            
    switch (mese) {
                   ^
      (use -source 
    7 or higher to enable strings in switch)
    Note: C:\Users\smamici\Desktop\SimpleLibraryCompiler\CodiceFiscale\src\com\codicefiscale\Lista.java uses unchecked 
    or unsafe operations.
    Note: Recompile with -Xlint:unchecked 
    for details.
    1 error
     
     
    Error.
    Any idea ??
    Thank you
    Marco
     
  2. MarcoRome

    MarcoRome Expert Licensed User

    To resolve this in Eclipse:

    Code:
    1.Right-click on your project(Package Explorer) and select "Android Tools -> Fix Project Properties"
    2.Right-click on your project and select "Properties -> Java Compiler", check "Enable project specific settings" and select 1.7 or 1.8 from "Compiler compliance settings" select box.
    3.then Rebuild your project (Project -> Clean)
    But into SLC ?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    I'm not sure which version of Java added support for this feature and I'm not sure that it will not cause problems with Android.

    I recommend you to switch to a HashMap instead it is more elegant and will just work.
     
    MarcoRome likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice