亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有關編程的菜鳥問題

有關編程的菜鳥問題

眼眸繁星 2019-03-22 18:13:02
先上代碼convertView.setOnClickListener(new OnClickListener() {    long lastClick;    @Override    public void onClick(View v) {        if (System.currentTimeMillis() - lastClick <= 1000) {        return;        }    lastClick = System.currentTimeMillis();     }});這樣寫是編譯通過的,但是如果我把long lastClick;放到onClick的里面第一行,然后再進行if來判斷,就會報錯要求對lastClick進行初始化,這時為什么啊?求解
查看完整描述

1 回答

?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

long lastClick放在 函數外, 是對象的成員變量, 默認初始化為0.

放在函數內, 稱為本地變量. JLS7, #16 里有寫:

"EACH local variable (§14.4) and every blank final field (§4.12.4,
§8.3.1.2) must have a definitely assigned value when any access of its
value occurs. An access to its value consists of the simple name of
the variable (or, for a field, the simple name of the field qualified
by this) occurring anywhere in an expression except as the left-hand
operand of the simple assignment operator = (§15.26.1). For every
access of a local variable or blank final field x, x must be
definitely assigned before the access, or a compile-time error occurs
"


查看完整回答
反對 回復 2019-04-15
  • 1 回答
  • 0 關注
  • 445 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號