If another statement at the same time, although it should not be possible

I am having a very strange problem in eclipse. Take a look at the following code:

public void addItem(ArrayList<Object> objectLists)  {

        SHorizontalLayout hLayout = Cf.hLayout();
        hLayout.setSizeFull();
        hLayout.setHeight(rowHeight, UNITS_PIXELS);
        if(rowCount % 2 != 0 && rowCount != 0)  {
            hLayout.addStyleName("row-even");
        } else  {
            hLayout.addStyleName("row-odd");            
        }

        for(Object object : objectLists)    {

            if(object instanceof String || object instanceof Integer)   {
                hLayout.addComponent(Cf.h1(object.toString()), Alignment.MIDDLE_CENTER);
                columnList.get(0).addComponent(hLayout);                
            } else if(object instanceof ChipSlotGrid)   {
                hLayout.addComponent((ChipSlotGrid)object, Alignment.MIDDLE_CENTER);
                columnList.get(1).addComponent(hLayout);            
            }
        }

        rowCount++;
    }

In a for loop, the object is checked for the instance type and appropriately added to the layout.

The problem I'm experiencing is that when the object is of type Integer, it enters the if statement, executes two lines inside the statement, and then instead of going into a new loop of the loop, it goes into the else statement executing the line columnList.get(1).addComponent(hLayout)(skipping first line in the else statement).

It executes parts of the else statement, even if it has already entered the if.I statement I know this because I see its product in the application that I am developing, and I saw it programmatically when I debug the code.

:

i = 0;    
if(true)   {
   i++;
} else   {
   i++;
}

System.out.println(i);

: 2

. - IDE? - - , ?

EDIT: , .

for(Object object : objectLists)    {

        if(object instanceof ChipSlotGrid)  {
            hLayout.addComponent((ChipSlotGrid)object, Alignment.MIDDLE_CENTER);
            columnList.get(1).addComponent(hLayout);                
        } else if(object instanceof String || object instanceof Integer)    {
                hLayout.addComponent(Cf.h1(object.toString()), Alignment.MIDDLE_CENTER);
                columnList.get(0).addComponent(hLayout);
        }
    }

2: Jon .

for(Object object : objectLists)    {

            if(object instanceof ChipSlotGrid)  {
                log.info("Inside if");
                hLayout.addComponent((ChipSlotGrid)object, Alignment.MIDDLE_CENTER);
                columnList.get(1).addComponent(hLayout);
            } else if(object instanceof String || object instanceof Integer)    {
                    log.info("Inside else");
                    hLayout.addComponent(Cf.h1(object.toString()), Alignment.MIDDLE_CENTER);
                    columnList.get(0).addComponent(hLayout);
            }
        }

if else, else. ( , , )

+5
4

:

if(object instanceof String || object instanceof Integer)   {
    hLayout.addComponent(Cf.h1(object.toString()), Alignment.MIDDLE_CENTER);
    columnList.get(0).addComponent(hLayout);                
} else if(object instanceof ChipSlotGrid)   
    hLayout.addComponent((ChipSlotGrid)object, Alignment.MIDDLE_CENTER);
    columnList.get(1).addComponent(hLayout);            

( else if), , .

, , , . , , IDE, , ? , JAR, .

+2

Eclipse Indigo. , , Eclipse . "" . , if, , , if .

+2

addItem SHorizontalLayout, columnList. , ?

, , objectLists Integer a ChipSlotGrid , SHorizontalLayout, Integer, 0, ChipSlotGrid , 1.

- , , 1, 0, Integer, ChipSlotGrid, , , if.

, , , , .

0

, addItem() . , rowCount addItem. for, int callCount - callCount++ for.

I am sure that it will be increased to 2, because it addItemreceives a call 2 times

0
source

All Articles