Results 1 to 6 of 6

Thread: Help!! Java 5, boxing and auto switch.

  1. #1
    Join Date
    Apr 2010
    Posts
    84

    Help!! Java 5, boxing and auto switch.

    I am facing the following problem. All case statements to work with all the wrappers as a switch statement, BUT when I use the Integer wrapper as a switch statement is no longer compile the non-int cases. I tested compiler 1.5 and 1.6 and in both I get the same compile error. I have found nothing in the JLS spec and no bug entry for SUN. also a coincidence that someone will link explains where, _way_ the steps occur at compile time to lay to construct the switch, ie, what steps does the compiler (including what is where when boxed / unboxt). Please help me as early as possible.

  2. #2
    Join Date
    Jan 2006
    Posts
    211

    Re: Help!! Java 5, boxing and auto switch.

    I think that you have not properly convoluted your query. You have not discussed about the "compile error" that you are getting. Also if you are using some coding (which is obvious), then it would be good for me (also others) to find out the errors from that coding. So don't hesitate to provide the coding that you are using.

  3. #3
    Join Date
    Apr 2010
    Posts
    84

    Re: Help!! Java 5, boxing and auto switch.

    I am extremely sorry for an inconvenience caused to you because of my improper query The following is the test code :
    Code:
    public class Test Switch 
    ( 
    
    public static void main (String [] args) 
    ( 
    final int iP = 1; 
    final short sP = 126; 
    final byte bP = 2; 
    Short SLW = 3; 
    Byte BLW = 4; 
    Character CLW = 5; 
    ILW Integer = 6; 
    
    // Switch (CLW) (// prima 
    // Switch (FOA) (// prima 
    // Switch (SLW) (// prima 
    switch (ILW) (// non-int cases - ERROR?? 
    case sP: 
    System.out.println (""); break; 
    case 'n': 
    System.out.println (""); break; 
    bP case: 
    System.out.println (""); break; 
    iP case: 
    System.out.println (""); break; 
    case 127: 
    System.out.println (""); break; 
    ) 
    ) 
    )
    the compile errors:
    MSAU @ lettuce: / export / home / MSAU / projects / playground / src / innerClasses> java-version
    java version "1.5.0_07"
    Java (TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
    Java HotSpot (TM) Server VM (build 1.5.0_07-b03, mixed mode)
    MSAU @ lettuce: / export / home / MSAU / projects / playground / src / innerClasses> ll
    total 20
    drwxr-xr-x 2 MSAU Domain Users 512 Jul 24 14:10.
    drwxr-xr-x 6 MSAU Domain Users 512 Jul 22 09:06 ..
    -Rw-r - r - 1 MSAU Domain Users 6692 Jul 22 12:09 InnerClassTest.java
    -Rw-r - r - 1 MSAU Domain Users 886 Jul 24 14:10 SwitchTest.java
    MSAU @ lettuce: / export / home / MSAU / projects / playground / src / innerClasses> javac SwitchTest.java
    SwitchTest.java: 25: incompatible types
    short found:
    required: java.lang.Integer
    case sP:
    ^
    SwitchTest.java: 27: incompatible types
    found: char
    required: java.lang.Integer
    case 'n':
    ^
    SwitchTest.java: 29: incompatible types
    found: byte
    required: java.lang.Integer
    bP case:
    ^
    3 errors

  4. #4
    Join Date
    Jan 2009
    Posts
    140

    Re: Help!! Java 5, boxing and auto switch.

    I have tested it in 2 different versions on 2 different OS and it will not compile. Do you have there income benefit with the "switch (ILW)" tried? Also I want to ask that are you using java version "1.5.0_07"? Java (TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03) Java HotSpot (TM) Server VM (build 1.5.0_07-b03, mixed mode).

  5. #5
    Join Date
    Jan 2006
    Posts
    211

    Re: Help!! Java 5, boxing and auto switch.

    I would strongly recommend you use an IDE. Eclipse will show example of exactly where the problem lies in your code. I would suggest simply times that you are using the wrong types of auto boxing. it can do only as from the primitive datatype in the wrapper class and vice versa give autoboxt.

  6. #6
    Join Date
    Aug 2006
    Posts
    162

    Re: Help!! Java 5, boxing and auto switch.

    I would suggest simply times that you are using the wrong types of auto boxing. it can do only as from the "primitive datatype in the wrapper class and vice versa give autoboxt.
    That’s the funny. If the wrapper "byte" is used, all are apparently not "byte-based" types accepted without a murmur. The same for "Short" and "Character". Only "Integer making" problems. I would like to understand exactly why we cannot. Because with auto boxing / unboxing cannot switch between various "hierarchies" as "Byte <-> Short" they both "just" extender of "Number". But why it is still except for "Integer".

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Switch in Java
    By cloud101 in forum Software Development
    Replies: 3
    Last Post: 19-01-2012, 07:04 PM
  3. IOGEAR Printer Auto Sharing Switch for Mac and Windows PC
    By Immortality in forum Portable Devices
    Replies: 4
    Last Post: 03-09-2010, 11:57 PM
  4. Auto switch timer in Nokia 5300
    By Bindusar in forum Portable Devices
    Replies: 3
    Last Post: 19-11-2009, 07:04 PM
  5. If / else / else if / switch box in Java
    By Samir_1 in forum Guides & Tutorials
    Replies: 2
    Last Post: 11-07-2009, 01:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,902,804.66158 seconds with 17 queries