本文介紹了類型不匹配:無法從整數轉換為布爾值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
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?
推薦答案
試試這個返回
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;
}
它繼續讓我感到困惑為什么人們使用 i
- 一個可怕的變量名.看起來像 1
并沒有傳達任何含義.
It continues to mystify me why people use i
-- a horrible variable name. Looks like 1
and does not convey any meaning.
這篇關于類型不匹配:無法從整數轉換為布爾值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!