提问人:tfrysinger 提问时间:9/9/2020 更新时间:9/9/2020 访问量:262
为什么 Android Studio Lint 在为 Java 8 支持添加了脱糖功能后,仍然会在 Date 函数上报告“在旧版本上调用新方法”?
Why does Android Studio Lint report "Calling new methods on older versions" on Date functions even after adding desugaring for Java 8 support?
问:
我安装了最新的 AS 4.01,并使用 coreLibraryDesugaring (1.0.10) 为 Java 8 支持设置了最新的依赖项,并在我的 build.gradle 文件中设置了适当的 compileOptions。以下代码在使用 API 23 的设备上编译并运行,不会出错:
TemporalAccessor ta = null;
Instant i;
Date date = null;
try {
int loc = 0;
if ((loc = publishedDate.indexOf("+")) > 0) {
// Offset time given
publishedDate = adjustTimeFormat(publishedDate, loc);
ta = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(publishedDate);
i = Instant.from(ta);
} else if ((loc = publishedDate.indexOf("-")) > 0) {
publishedDate = adjustTimeFormat(publishedDate, loc);
ta = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(publishedDate);
i = Instant.from(ta);
} else if (publishedDate.contains("Z")) {
i = Instant.parse(publishedDate);
} else {
//
ta = DateTimeFormatter.ISO_DATE.parse(publishedDate);
i = Instant.from(ta);
}
date = Date.from(i);
} catch (Exception e) {
ta = null;
}
if (ta == null) {
date = new Date();
}
return date;
但是,lint 将其中许多行标记为“需要 API 级别 26(当前最小值为 21)”
我以为脱糖到位后,它应该允许这样做吗?这是棉绒虫吗?
答: 暂无答案
评论
else
ISO_DATE
Instant
DateTimeException
Instant