android中lambda运算符出错
我想使用lambda运算符使用Runnable方法编写代码,但我得到了一个错误 错误:(40,33)错误:lambda表达式在-source 1.7中不受支持 (使用-source 8或更高版本来启用lambda表达式) 这是我的密码:`android中lambda运算符出错,android,Android,我想使用lambda运算符使用Runnable方法编写代码,但我得到了一个错误 错误:(40,33)错误:lambda表达式在-source 1.7中不受支持 (使用-source 8或更高版本来启用lambda表达式) 这是我的密码:` public void countDownStart(){ handler= new Handler(); runnable= (Runnable) () -> { handler.postDelayed((Runnable
public void countDownStart(){
handler= new Handler();
runnable= (Runnable) () -> {
handler.postDelayed((Runnable) this, 1000);
try{
SimpleDateFormat dateFormat= new SimpleDateFormat("YYYY-MM-DD");
Date futureDate= dateFormat.parse("2017-03-31");
Date currentDate= new Date();
if (!currentDate.after(futureDate)){
long diff = futureDate.getTime()- currentDate.getTime();
long days = diff / (24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
long hours = diff / (60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
long minutes = diff / (60 * 1000);
diff -= minutes * (60* 1000);
long seconds = diff / 1000;
txtTimerDay.setText("" + String.format("%02d", days));
txtTimerHour.setText("" + String.format("%02d", hours));
txtTimerMinute.setText("" + String.format("%02d", minutes));
txtTimerSecond.setText("" + String.format("%02d", seconds));
}else{
tvEvent.setVisibility(View.VISIBLE);
tvEvent.setText("The Event Started");
textViewGone();
}
} catch (Exception e){
e.printStackTrace();
}
};
handler.postDelayed(runnable, 1 * 1000);
}
您是否在build.gradle文件中添加了以下说明
defaultConfig {
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
您正在使用Java7。自Java8以来,lambda表达式一直受支持。android的问题是,只有android n(7.0)或更高版本支持Java8。如果您仍然希望在较低的android版本中使用lambdas,可以使用类似的库,但这些库通常不支持java lambdas的所有功能 你的JAVA verson是什么?你在谷歌上搜索过错误信息吗?