Type mismatch: cannot convert from integer to boolean

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.


May be you can just modify your return statement without much change to code as below:

return i > 0 ? true : false ;

Convert int to boolean:

return i > 0;

I know this thread is old but wanted add some code that helped me and might help others searching this...

You could use org.apache.commons.lang api to convert an int to boolean using the BooleanUtils class:

BooleanUtils.toBoolean(int value)

"Converts an int to a boolean using the convention that zero is false." (Javadocs)


Here are the Maven & Gradle dependencies, just make sure you check you're using the latest version on the link http://mvnrepository.com/artifact/org.apache.commons/commons-lang3

Maven Dependency:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.4</version>
</dependency>

Gradle Dependency:

'org.apache.commons:commons-lang3:3.4'