Results 1 to 3 of 3
  1. #1
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

    Default switch are not supported in -source 1.5

    Hello All,

    I am trying to use switch statement on String .. but the compiler gives me:
    "strings in switch are not supported in -source 1.5 use source-7 or higher to enable strings in switch)

    any idea for doing this?

    Java Code:
    String kode1 = akode1[0];
    String kode2 = akode2[1];
    switch (kode1) {
    case "A":
    break;
    case "X":
    break;
    case "S":
    break;
    case "E":
    break;
    case "C":
    break;
    Default:
    break;
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by newbiejava View Post
    Hello All,

    I am trying to use switch statement on String .. but the compiler gives me:
    "strings in switch are not supported in -source 1.5 use source-7 or higher to enable strings in switch)

    any idea for doing this?
    Yep, the compiler is right (as always): you can only use ints for the switch statement. If you want to use Strings you either have to use a sequence of if-else-if-else statements or a Map<String, Runnable> or equivalent.

    kind regards,

    Jos

  3. #3
    newbiejava is offline Senior Member
    Join Date
    Jan 2010
    Posts
    138
    Rep Power
    0

Similar Threads

  1. best java supported!!
    By cpanel in forum Reviews / Advertising
    Replies: 4
    Last Post: 01-10-2011, 06:54 PM
  2. python source to java source converter?
    By conor147 in forum New To Java
    Replies: 0
    Last Post: 01-15-2010, 06:14 AM
  3. StringTokeingizer class not supported by IDE
    By piyushdhamija in forum NetBeans
    Replies: 0
    Last Post: 03-20-2009, 01:16 PM
  4. Replies: 0
    Last Post: 01-29-2009, 11:43 AM
  5. Replies: 1
    Last Post: 11-28-2008, 07:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •