第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

有關(guān)編程的菜鳥(niǎo)問(wèn)題

有關(guān)編程的菜鳥(niǎo)問(wèn)題

眼眸繁星 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();     }});這樣寫(xiě)是編譯通過(guò)的,但是如果我把long lastClick;放到onClick的里面第一行,然后再進(jìn)行if來(lái)判斷,就會(huì)報(bào)錯(cuò)要求對(duì)lastClick進(jìn)行初始化,這時(shí)為什么?。壳蠼?
查看完整描述

1 回答

?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊

long lastClick放在 函數(shù)外, 是對(duì)象的成員變量, 默認(rèn)初始化為0.

放在函數(shù)內(nèi), 稱為本地變量. JLS7, #16 里有寫(xiě):

"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
"


查看完整回答
反對(duì) 回復(fù) 2019-04-15
  • 1 回答
  • 0 關(guān)注
  • 442 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)