Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

java - Type mismatch: cannot convert from integer to boolean

public boolean clearSelection() {
    int i = 0;
    if (!this.m_SelectedComps.isEmpty()) {
        i = 1;
        Iterator localIterator = this.m_SelectedComps.iterator();
        while (localIterator.hasNext())
            ((AnnotComponent) localIterator.next()).remove();
        this.m_SelectedComps.clear();
    }

    return i;
}

How to convert the integer to boolean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try using this return

return i == 1;

or just use a boolean to start (with a better name):

 public boolean clearSelection()
  {
    boolean flag = false;
    if (!this.m_SelectedComps.isEmpty())
    {
      flag = true;
      Iterator localIterator = this.m_SelectedComps.iterator();
      while (localIterator.hasNext())
        ((AnnotComponent)localIterator.next()).remove();
      this.m_SelectedComps.clear();
    }
    return flag;
  }

It continues to mystify me why people use i -- a horrible variable name. Looks like 1 and does not convey any meaning.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...