0

Hi guys i got such kind of troubleObject name insted of caption

In dialog w/ combo box

    public JComboBox<IngrMeasureUnit> getUnits(){
     JComboBox<IngrMeasureUnit> result = new JComboBox<IngrMeasureUnit>();
        for ( int i = 0; i < parent.getIngrList().imul.getSize(); i++ ) {
            result.addItem(parent.getIngrList().imul.getMeasureUnit(i));
        }        
     return result;
}

And the class

public class IngrMeasureUnit {

private int id;
private String name;
private boolean mustInt;

public IngrMeasureUnit( int id, String name, boolean mustInt ) {
    this.id = id;
    this.name = name;
    this.mustInt = mustInt;
}

public String toSrting() {
    return name;
} 

Cannot understand such behauviour, because in other cases it works. Tried to put @Override annotation, the compiler rejected it. Thanks.

4

1 に答える 1

1

Your method is named toSrting() instead of toString(). Always use the @Override annotation when your intention is to override a method. That way, if you don't, the compiler will emit an error:

@Override
public String toSrting() { // compiler error, because toSrting() doesn't override anything

Tried to put @Override annotation, the compiler rejected it.

The compiler rejected it precisely because the method doesn't override anything. The error means: you want to override a method, but you don't. Something is wrong. Instead of removing the annotation in this case, you should fix the method signature.

于 2013-01-05T08:21:48.240 に答える