Why "null" value is impossible in "switch(val) {case null: }"  for enums?

I'm wondering why Java 5.0 does not allow null values
as options in switch statement:
If type E is "enum" then the following language construction is
not allowed:
E val;
switch(val) {
   case A:
     break;
   case B:
       break;
   case null:   // this is not allowed
        break;
}Can somebody explain me why Java does not support it? I beleave that
some serious reasons were for that.
As we know enum types can have "null" values and in case I use nulls
for my enumerations the code with "switch" statement becomes quite urgly because it is necessary to handle 2 separate execution paths:
null and not null.
Thanks

I really don�t know too much about 1.5, but I can tell you that for 1.4 the switch receives as a parameter an int or anything that can be casted automatically to an int. Therefore you can�t never use null cause int, char, short, byte can�t never take as a value null.

Similar Messages

  • Switch statement with println() for enum

    Hi,
    I have this exercise maybe you could help with:
    I have to create an enum class and then print out a description of each of the values from a switch.
    This is what I've done..
    enum PaperCurrency {
         FIVE, TEN, TWENTY, FIFTY, ONE_HUNDRED, TWO_HUNDRED
    public class Ex22 {
         PaperCurrency amount;
         Ex22(PaperCurrency amount) {
              this.amount = amount;
         void describe() {
              switch(amount) {
              case FIVE:               System.out.println("five dollar note");
              case TEN:               System.out.println("ten dollar note");
              case TWENTY:          System.out.println("twenty dollar note");
              case FIFTY:               System.out.println("fifty dollar note");
              case ONE_HUNDRED:     System.out.println("a hundred dollar note");
              case TWO_HUNDRED:     System.out.println("two hundred dollar note");
    static void main(String[] args) {
              Ex22
                   fiveDollars = new Ex22(PaperCurrency.FIVE),
                   tenDollars = new Ex22(PaperCurrency.TEN),
                   twentyDollars = new Ex22(PaperCurrency.TWENTY),
                   fiftyDollars = new Ex22 (PaperCurrency.FIFTY),
                   aHundredDollars = new Ex22 (PaperCurrency.ONE_HUNDRED),
                   twoHundredDollars = new Ex22 (PaperCurrency.TWO_HUNDRED);
              fiveDollars.describe();     
    }There are no compilation errors.
    The print out on the console is like this for fiveDollars.describe():
    five dollar note
    ten dollar note
    twenty dollar note
    fifty dollar note
    a hundred dollar note
    two hundred dollar note
    and it is supposed to be:
    five dollar note.
    My question is how to only print out the relevant description instead of all of them? Is my switch wrong?
    Thanks for any help

    If you can, it makes more sense to add functionality to an enum type than to write switch statements:
    public enum PaperCurrency {
        FIVE("five dollar note"),
        TEN("ten dollar note"),
        TWENTY("twenty dollar note"),
        FIFTY("fifty dollar note"),
        ONE_HUNDRED("one hundred dollar note"),
        TWO_HUNDRED("two hundred dollar note");
        private String description;
        private PaperCurrency(String desc) {
            description = desc;
        public String getDescription() {
            return description;
        public static void main(String[] args) {
            System.out.println(PaperCurrency.TEN.getDescription());
    }

  • Why the values of these parameters can not be listed?

    Why the values of these parameters can not be listed?
    SQL> show parameter nls_time_format;
    NAME                                 TYPE        VALUE
    nls_time_format                      string
    SQL> show parameter nls_date_format;
    NAME                                 TYPE        VALUE
    nls_date_format                      string

    qkc wrote:
    Do you mean the values are NULL? Why the default value not liested here.This is from my sandbox 10.2.0.4 database on linux. This was built just a few days ago and is absolutely default in all respects:
    SQL> show parameter nls
    NAME                                 TYPE        VALUE
    nls_calendar                         string
    nls_comp                             string
    nls_currency                         string
    nls_date_format                      string
    nls_date_language                    string
    nls_dual_currency                    string
    nls_iso_currency                     string
    nls_language                         string      AMERICAN
    nls_length_semantics                 string      BYTE
    nls_nchar_conv_excp                  string      FALSE
    nls_numeric_characters               string
    nls_sort                             string
    nls_territory                        string      AMERICA
    nls_time_format                      string
    nls_time_tz_format                   string
    nls_timestamp_format                 string
    nls_timestamp_tz_format              string
    SQL>Besides, it is a bad idea to depend on the defaults anyway. There are so many places they can be overridden that it is foolish for an app to depend on it. Rather, you should always be using (properly) the to_char and to_date functions to specify the formats at the individual sql statement. So the 'default' values become totally irrelevant.

  • Using MISSING FIELD VALUES ARE NULL for external table

    I want to place a null for values missing in the sub_account field. Here is my external table:
    CREATE OR REPLACE DIRECTORY INCOMING_ORDERS_log_dir
    AS 'c:\starpubs\starpubs\dataformats\logs\INCOMING_ORDERS\log';
    CREATE OR REPLACE DIRECTORY INCOMING_ORDERS_bad_dir
    AS 'c:\starpubs\starpubs\dataformats\logs\INCOMING_ORDERS\bad';
    create table ext_INCOMING_ORDERS_table (
    Account varchar(5),
    Sub_Account varchar(1),
    Override_Code varchar(1),
    Nomenclature varchar(28),
    chg_nbr varchar(3),
    quantity integer,
    U_I varchar(5),
    zipcode varchar(5),
    type_reject varchar(2)
    organization external
    type oracle_loader
    default directory user_dir
    access parameters
    records delimited by newline
    missing field values are null
    badfile INCOMING_ORDERS_bad_dir:'INCOMING_ORDERS%a_%p.bad'
    logfile INCOMING_ORDERS_log_dir:'INCOMING_ORDERS%a_%p.log'
    fields
    Account(1:5) char(5),
    Sub_Account(7:7) char(1),
    Override_Code(10:10) char(1),
    Nomenclature(11:38) char(28),
    chg_nbr(40:42) char(3),
    quantity(44:48) integer external,
    U_I(50:54) char(5),
    zipcode(56:60) char(5),
    type_reject(61:62) char(2)
    location('PTCLICK.MANUAL.NOMEN.TXT','PTCLICK.ORDERS.TXT', 'EUR_RES.TXT', 'MQ.TXT', 'BPRO.TXT')
    reject limit unlimited;
    How can I place the MISSING FIELD VALUES ARE NULL for missing values for the sub_account?

    made the change I received this error:
    SQL> select * from ext_INCOMING_ORDERS_table;
    select * from ext_INCOMING_ORDERS_table
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-00554: error encountered while parsing access parameters
    KUP-01005: syntax error: found "no": expecting one of: "comma, date_format,
    defaultif, enclosed, ltrim, lrtrim, ldrtrim, notrim, nullif, optionally, ),
    rtrim, terminated"
    KUP-01007: at line 7 column 26
    CREATE OR REPLACE DIRECTORY INCOMING_ORDERS_log_dir
    AS 'c:\starpubs\starpubs\dataformats\logs\INCOMING_ORDERS\log';
    CREATE OR REPLACE DIRECTORY INCOMING_ORDERS_bad_dir
    AS 'c:\starpubs\starpubs\dataformats\logs\INCOMING_ORDERS\bad';
    create table ext_INCOMING_ORDERS_table (
    Account varchar(5),
    Sub_Account varchar(1),
    Override_Code varchar(1),
    Nomenclature varchar(28),
    chg_nbr varchar(3),
    quantity integer,
    U_I varchar(5),
    zipcode varchar(5),
    type_reject varchar(2)
    organization external
    type oracle_loader
    default directory user_dir
    access parameters
    records delimited by newline
    badfile INCOMING_ORDERS_bad_dir:'INCOMING_ORDERS%a_%p.bad'
    logfile INCOMING_ORDERS_log_dir:'INCOMING_ORDERS%a_%p.log'
    fields
    Account(1:5) char(5),
    Sub_Account(7:7) char(1) NO PRESERVE BLANKS,
    Override_Code(10:10) char(1),
    Nomenclature(11:38) char(28),
    chg_nbr(40:42) char(3),
    quantity(44:48) integer external,
    U_I(50:54) char(5),
    zipcode(56:60) char(5),
    type_reject(61:62) char(2)
    location('PTCLICK.MANUAL.NOMEN.TXT','PTCLICK.ORDERS.TXT', 'EUR_RES.TXT', 'MQ.TXT', 'BPRO.TXT')
    reject limit unlimited;

  • Why does firefox autostart when I switch computer on

    why does firefox autostart when I switch computer on

    [[Firefox launches automatically when your computer starts]]
    If you have nothing Firefox related in your startup folder,
    Your issue may be caused by Malware. You can run and update the following '''free''' anti virus software:
    1. Malwarebytes (Free version) - http://www.malwarebytes.org
    2. Spybot Search & Destroy - http://www.safer-networking.org
    3.Spyware Terminator - http://www.spywareterminator.com
    In addition, there are a number of forums you can use to help get rid of your infection. These include:
    *[http://www.bleepingcomputer.com/forums/ Bleeping Computer]
    *[http://forums.spybot.info/ Safer-Networking Forums]
    *[http://www.spywarewarrior.com/index.php Spyware Warrior Forums]
    *[http://www.spywarewarrior.com/index.php SpywareInfo Forums]

  • Why loading values... is populating in custom option lists

    I have created the option list and i have added the values from the view. But values are not gettiing populated in the check-in form. why loading values... is populating in custom option lists

    We have encountered a similar issue again. Therefore, I did a bit of a deeper request. I will write my findings, plus there are still few open questions.
    First, the customer's issue: the customer wants to have its supplier's ids in documents' metadata. Vendors are populated to a custom database table in UCM's database from a third party system. The customer complains that updates to the custom table were not populated (they do updates in 30 minutes).
    a) "loading values" reproduced: I tried to repeat the scenario as described in this issue with Srinath's advices. Even when I did Publish Schema/Publish Schema Base, the issue persisted. The one thing I had to do above that was restarting the browser (I used Mozilla Firefox). Therefore, I assume that values are cached somewhere in the browser and need to be refreshed first (no error in the log)
    Q1: Does anybody have a clue how this could be automated? I clicked Check In New - Standard, so I would expect the values to be refreshed
    b) I checked the relevant part in the manual (+Managing Repository Content+, chapter 7) and there I found this:
    New or modified schemas are automatically updated during each scheduled publishing cycle. Because the default interval between each publishing cycle is set to four hours, you will not see immediate results for new or modified schemas. You can, however, adjust the interval between each publishing cycle by changing the default value of a configuration variable. For more information, see Modifying the Publishing Cycle Interval (page 7-12).
    This explains the behavior and confirms Srinath's advices.
    c) now, I created a testing table, view, and metadata field, linked it together following the advices. When I got it working I added a new value to the table in the database to find out that I am in problems again - at least this time, Publish Schema/Publish Schema Base did not seem to work for me and I had to restart the content server (which is hardly something I can do every 30 mins like our customer wants).
    Q2: Is there a way how to force population of database table updates to views/option lists in UCM?

  • Why "condition value column" is there 2times in sales order under condition

    Hi Friends,
    Can any one say that why "condition value column" is there 2 times under condition tab  in sales order and in which scenario it will be useful.
    Thanks in advance
    JM.

    Hi JM,
    Suppose you r using conduction XYZ ok for that xyz conduction one access sequence is maintain for example AOO1 ok now just go in V/07 tcode for access sequence select your access sequence AOO1 from given option go inside one exclusion indicator is their make sure it is market tick for all access  
    If u r not clear.
    U r always welcome to ask question.
    Ahmed

  • TS3772 Just because I live in Thailand it doesn't mean I want all the pop-up boxes to be Thai! Why is there no box to switch languages?

    Why is there no box to switch languages?  Just because I live in Thailand doesn't mean that I read and write in Thai.  Please include a language box to switch languages at the front end of download pages and other places as needed.

    Only Apple could answer as to why there is no "select all/"delete all" function in the iOS mail app. Users have been bemoaning this lack of functionality for years now. Like everyone else, you can submit feedback to. Apple here.
    Apple - iPhone - Feedback
    While I understand the whole idea of being able to use the phone on the run, if you have an IMAP email account, and if you have access to a computer at work during the day, use your "select all" function on the server and delete all of the unwanted email there and it will be removed from the phone as well.
    That doesn't solve the problem on the phone, but it gets rid of the email which is your ultimate goal anyway.

  • Why does my loud speaker keep switching itself on my iphone

    why does my loud speaker keep switching itself on my iphone.Every time I'm on my phone the loud speaker keeps coming on autermaticly

    Call AppleCare (number is in the manual) and then request to speak to Customer Service. Be patient, organized and articulate and they will transfer you. When you get to speakt to someone then explain your problem and ask for their help. You should have all your receipts, invoices, trouble ticket numbers etc available for reference.
    You can also take to an Apple Store in Spain, while this may not be convenient at least then an Apple person can see the machine and work on it.

  • Why header value not in Item table

    hi sapgurus
        why the value of VBAK-VBELN not present in its item table VBAP-VBELN.plz give reason.
        thankx in advance..

    HI Rakesh,
    If u r talking about the whole record in VBAP then it is possible. But if it is only with the field VBELN then ideally its not possible. But some one has modified VBAP table data from SE16N transaction.
    When we create an order VBAK and VBAP tables will be filled with header and item details. But later
    If u delete all the line items from the order then in ur VBAP table there won't be any entries for that VBELN while ur VBAK still have an entry. Just open that order in VA03 and see if it has any line items. I hope there won't be any.
    If u need still more clarity then create an order and check the tables. Later delete all the line items from the order and check the atbles again.
    Thanks,
    Vinod.

  • Hi why cannot turn off the zoom switch

          Hi why cannot turn off the zoom switch and maybe is affecting the waze app the screen is half black only in these app  , but for example whe I tried to add the photo below the menu to add the photo just appear half and I couldn't read the right portion of it like it is out of focus I tried several times

    HI and welcome to Apple Discussions...
    Perhaps you have an app running. Try force quitting.
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until you see the Apple logo.
    If that doesn't make a difference, reset your iPad. Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds until you see the Apple logo.
    Make sure your iPad software is up to date. Connect the iPad to your computer. Launch iTunes if it doesn't open automatically. Under the Summary tab click: Check for Update
    Carolyn

  • Im trying to download In-game content on Madden Social, but when i press buy it says " Contact iTunes support to proceed with transaction " I contacted them, but does anyone know why this happens? I recently switched my apple ID

    Im trying to download In-game content on Madden Social, but when i press buy it says " Contact iTunes support to proceed with transaction " I contacted them, but does anyone know why this happens? I recently switched my apple ID

    Im trying to download In-game content on Madden Social, but when i press buy it says " Contact iTunes support to proceed with transaction " I contacted them, but does anyone know why this happens? I recently switched my apple ID

  • Why am I getting the error "Coercion Failed: Input cannot be null for this coercion"?

    I created a OOTB team site, with a OOTB document library and an OOTB "Approval - SharePoint 2010" workflow.  Under the workflow's start options I have "Allow this workflow to be manually..." checked.  On the next workflow setup page, I put
    myself in the Assign To field and put "test" in the Request field.  I left everything else blank. 
    Then, I setup a retention stage in the Information Management Policy settings for the library.  The event is Modified + 1 days, action is Start a workflow and I selected the workflow described above.  I set the Recurrence for 1 days.
    If I execute the workflow manually, it executes without error. 
    When the IMP executes the workflow, the status indicated in the column added to the library is "Canceled".  Clicking on the Canceled link opens the Workflow Information.  In the Workflow History section the Event Type is Error, User ID is System
    Account and Description is "Coercion Failed: Input cannot be null for this coercion". 
    Research shows that this error can be invoked when creating custom workflows that contain empty input fields when executed.  I would think that if there were required input fields in the workflow
    configuration, that the workflow would error when manually executed. 
    Any help is appreciated.  Thank you.
    Matt H.

    I had found that article previously but it doesn't seem to apply since this is OOTB and not a workflow created in SD.  I would expect that MS would have created the workflow in such a manner that it would work with IMP.  Besides, I don't think
    it's possible to edit the default Approvers workflow.  Also, I'm sure I'm not the first one out there to use the Approvers workflow with IMP.  If it was broken OOTB, someone else would have discovered it.  My guess is that there is something
    not configured correctly on the server, but I don't know how to start to diagnose it based on this error message.Matt H.

  • SWITCH and CASE STATEMENT

    i am trying to use switch statement for drawing different shapes by clicking shapes buttons (eg line ,rectangle oval etc) . i have got a method called setDrawMode and i am passing shape value as parameter to this method but nothing happen .all it is doing is drawing with default value.
    my code for clicking button:
    String s = event.getActionCommand();
    if (s.equalsIgnoreCase("LINE"))
    {   mycanvas.setDrawMode(0);}
    else if (s.equalsIgnoreCase("RECTANGLE"))
    {  mycanvas.setDrawMode(1);}
    else if (s.equalsIgnoreCase("OVAL"))
    {  mycanvas.setDrawMode(2);}my setDrawMode method:
    public void setDrawMode(int mode)
    switch (mode)
    case LINE :
    case RECTANGLE:
    case OVAL:
    this.mode = mode;
    break; default:
    throw new IllegalArgumentException();
    }my code for paint method:
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    if (numPoints>0)
    for (int i=0; i<numPoints-1; i+=2)
    switch (mode)
    case LINE:
    g.drawLine(p.x,p[i].y,p[i+1].x,p[i+1].y);
    g.drawLine(p[numPoints-1].x,p[numPoints-1].y,cx,cy);
    break;
    case RECTANGLE:
    g.drawRect(p[i].x,p[i].y,p[i+1].x,p[i+1].y);
    g.drawRect(p[numPoints-1].x,p[numPoints-1].y,cx,cy);
    break;
    case OVAL:g.drawOval(p[i].x,p[i].y,p[i+1].x,p[i+1].y);
    g.drawOval(p[numPoints-1].x,p[numPoints-1].y,cx,cy);
    break;
    values for shapes
    int LINE = 0
    int RECTANGLE = 1
    int OVAL = 2
    please help
    khurram

    what is the point of this switch here?
    public void setDrawMode(int mode)
         switch (mode)
             case LINE :
             case RECTANGLE:
             case OVAL:
             this.mode = mode;
             break;
             default: throw new IllegalArgumentException();
    } This dosn't do anything but asign mode to the global mode, which is why you get the same value every time. You need to do something in the switch and you don't have a break between them so they would all execute anyway. You can try this.
    public void setDrawMode(int mode)
         switch (mode)
             case LINE : this.mode = 0;
             break;               
             case RECTANGLE: this.mode = 1;
             break;
             case OVAL: this.mode = 2;
             break;
             default: throw new IllegalArgumentException();
    }But if your just trying to set a global mode you could just ommit the switch because its redundant
    public void setDrawMode(int mode)
           this.mode = mode;
           // then you could call paint however you call it
           paintComponent(this.getGraphics);
    }

  • NULL vs NOT NULL for end effectivity

    I am working on a data model that needs to keep track of the properties of a company asset as of certain dates. In short my table looks like this:
    (loc is a FK but for this example i made it more legible)
    create table assets
      asset_id     number,
      asset_no     number,
      loc          varchar2(20),
      eff_start_dt date,
      eff_end_dt   date 
    asset_id  asset_no  loc         eff_start_dt  eff_end_dt
    1         1         san diego   10-may-09     13-may-09
    2         1         los angeles 13-may-09     14-may-09
    3         1         sacromento  14-may-09     null
    4         2         san diego   10-may-09     19-may-09
    5         2         bakersfield 19-may-09     nullLong story short there was a debate on weather or not the "eff_end_dt" should be null for the current location or if it should be some predetermined date far off into the future like 01-JAN-99. Is one method truly better than the other or should we just pick one and write our queries accordingly.
    Cheers,
    Tyson Jouglet

    Not trying to be the devil's advocate, as I agree on using nulls to represent unknown values, still some authors like CJ Date and others say that using nulls should be avoided. Much of that is based on relational theory though, and in practical real life it becomes much harder to make your data model (and your application) null-proof. Better live with it in my opinion, since SQL and relational databases rely on it. One just has to know how to deal with null properly.
    http://www.dcs.warwick.ac.uk/~hugh/TTM/Missing-info-without-nulls.pdf
    http://www.snopes.com/autos/law/noplate.asp
    http://tkyte.blogspot.com/2009/10/back-from-oracle-openworld.html

Maybe you are looking for

  • Welcome home 24" iMac!

    Well, I am finally the proud new owner of a new 24" iMac 3.06GHz! Swapped out the two 1GB GB RAM sticks for two 2GB for a total of 4GB. Watched a DVD movie to make sure the drive works. Ran perfect. Ran PiXel Check and found one dead pixel in the bla

  • Itunes stopped working error on launch win7 64bits

    Hello Everytime i try to open the app i get this error! ITUNES STOPPED WORKING and itunes crash.

  • Pricing not determined based on Customer hierarchy

    Hi All, I searched the forum for the specific issue, but could not find a proper solution. I have a specific scenario where we are migrating from 4.6C to 6.0.  The hierarchy is already maintained in 6.0 version in a way which we need to adopt it.  Th

  • After Panic Alert iPhoto Gone from Screensaver

    I removed the electric charge from the pc and placed pc on a chair.  Picked up pc by lower left hand side. Screensaver went horizontal w/waves moving left to right.  Three alarms sounding like an air raid alert, going down in the North Atlantic aboar

  • Azure to Azure Migration Cloning between subscriptions

    What is the best way to clone a configuration of VMs (Biztalk, SQL, 2012 Server, etc..) from one subscription to another? Is it possible to build a shell configuration of VMs in a Virtual Network and clone it to another subscription?   So this is not