获得此版本的 Android Studio 后,我可以在我的项目中使用JDK17 。一切都工作得很好,没有构建失败,没有运行时错误等(就像增强型开关工作正常)......但是这个警告在每次构建期间不断出现。有什么办法可以抑制这种情况吗?
(警告文本 -> “一个或多个类的文件版本 >= 56,不受官方支持”)
这些是 build.gradle 文件:
(1):-
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-rc01'
classpath 'com.google.android.gms:strict-version-matcher-plugin:1.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
(2):-
apply plugin: 'com.android.application'
apply plugin: 'com.google.android.gms.strict-version-matcher-plugin'
android {
compileSdkVersion 32 …Run Code Online (Sandbox Code Playgroud) 在 Java 中,Locale定义了与人们希望如何看待事物相关的事物(例如货币格式、月份名称以及一周的开始时间)。
当解析月份的名称(带有DateTimeFormatter)时,它开始变得棘手。
如果您使用Locale.US或Locale.ENGLISH则九月有缩写形式Sep。
如果您使用Locale.UK,那么 September 在 Java 11 中也有缩写形式Sep……但是当您尝试 Java 17 时,它就会有Sept(因为 Unicode CLDR 端发生了变化,我询问这是否正确)。
结果是,当我尝试使用 Java 17 进行构建时,我的测试开始失败。
我当前的代码使用Locale.UK而不是Locale.ENGLISH因为在Java中Locale.ENGLISH实际上不仅是英语,而且还是非ISO美国定义一周的方式(他们使用星期日作为一周的第一天)。我想以 ISO 方式获得它。
简单地:
WeekFields.ISO= WeekFields.of(Locale.UK)=WeekFields[MONDAY,4]WeekFields.of(Locale.ENGLISH)= WeekFields.of(Locale.US)=WeekFields[SUNDAY,1]因此,从 Java 17 开始,我还无法找到可以正常工作的内置语言环境。
在我看来,我必须选择Locale.ENGLISH并将9 月的简称更改为我需要的WeekFields。Locale.UK
我的问题是如何做到这一点(在 Java 17 中)?
或者有更好的方法来解决这个问题吗?
更新1:
密封类可以列出的子类的最大数量是多少(类似于接口):
public sealed class Foo permits A, B, C {
// How many sub classes can ^^^^^^^
// be listed here?
}
Run Code Online (Sandbox Code Playgroud)
该语言实际上是否定义了限制?即,在语言层面上它实际上是无限的吗?
如果语言层面没有这样的限制,那么似乎实现仍然必须有技术限制。某个地方应该有一个列表来存储允许的子类的某种表示形式。我希望那时使用 16 或 32 位整数。
我正在尝试构建我的办公室项目,我已从 java 11 升级到 17。
我已经根据兼容的java版本更新了我的maven,并且在针对其余错误获得了大量帮助后,我仍然停留在这个问题上。
到目前为止我已经更新的东西:
Eclipse版本,java版本,java版本,surefire插件详细信息,settings.xml中的mirrorOf标签。
版本详情如下:
Java 版本 - 17 。
Java 主页 - C:\Program Files\Java\jdk-17.0.5
java 路径 - C:\Program Files\Java\jdk-17.0.5\bin -
我的 pom 中的 java 版本 - 17
我的系统中安装的 maven 版本 - 3.8.5
maven_home - C:\project\Softwares\Maven\apache-maven-3.8.5\bin
我的 pom.xml 中的 Maven - 3.8.1
现在设置完所有内容后,这就是错误。请帮助我纠正这个问题:
Unable to load the mojo 'war' in the plugin 'org.apache.maven.plugins:maven-war-plugin:2.2' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: Cannot access defaults field of Properties
Run Code Online (Sandbox Code Playgroud)
编辑 1:添加 pom.xml 4.0.0
如果我声明以下密封层次结构
package a;
import b.B;
public sealed interface A permits B {
}
Run Code Online (Sandbox Code Playgroud)
package b;
import a.A;
public record B() implements A {
}
Run Code Online (Sandbox Code Playgroud)
不使用模块(没有 module-info.java)并尝试用 Maven 编译它我得到
[ERROR] .../src/main/java/a/A.java:[5,35] class a.A in unnamed module cannot extend a sealed class in a different package
Run Code Online (Sandbox Code Playgroud)
我知道https://openjdk.java.net/jeps/409和本节:
由 permit 指定的类必须位于超类附近:在同一个模块中(如果超类在命名模块中)或在同一个包中(如果超类在未命名模块中)。
但是,Maven 在编译时不应该默认使用类路径吗?能否完全避免这种限制?
如果不是,这不是开创了一个先例,其中模块路径上的功能比类路径上的功能更灵活,反过来 - 虽然仍然支持类路径,但与模块路径相比,它不像以前那样是一等公民?
我有一个使用 Eclipse 2022-03 和 OpenJDK 17 的 Java 17 项目:
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用新的 Java 17 开关功能,因此我在方法中尝试了以下方法:
return switch(testEnum) {
case foo -> newFoo();
case bar -> newBar();
}
Run Code Online (Sandbox Code Playgroud)
效果很好。但后来我尝试了这个(因为该值可能是null):
return switch(testEnum) {
case foo -> newFoo();
case bar -> newBar();
case null -> newDefault();
}
Run Code Online (Sandbox Code Playgroud)
Eclipsenull用红色下划线表示:
Switch 中的模式匹配是一项预览功能,默认情况下处于禁用状态。使用 --enable-preview 启用
通过 Maven 编译会产生:
[ERROR] /project/src/main/java/com/example/FooBar.java:[432,38] null in switch cases …Run Code Online (Sandbox Code Playgroud) 对我来说,要为此给出一个合适的标题很复杂。但一个例子应该会让事情变得简单得多。假设我有这个:
final class Cache {
private static final ConcurrentHashMap<String, List<String>> CACHE = ...
static List<String> byName(String name) {
return CACHE.computeIfAbsent(name, x -> // some expensive operation)
}
}
Run Code Online (Sandbox Code Playgroud)
这个想法可能很简单,它充当 LoadingCache,很像番石榴或咖啡因(实际上它更复杂,但这与问题无关)。
我希望能够判断这是第一次加载到缓存中,还是读取现有映射。目前,我这样做:
final class Cache {
private static final ConcurrentHashMap<String, List<String>> CACHE = ...
static List<String> byName(String name) {
boolean b[] = new boolean[1];
List<String> result = CACHE.computeIfAbsent(name, x -> {
b[0] = true;
// some expensive operation)
});
if(b[0]) {
// first load into the cache, do X
} else …Run Code Online (Sandbox Code Playgroud) 在 IntelliJ 中,当我对从 start.spring.io 下载的新项目进行干净构建时,会出现错误。
我已经安装了直接从 IntelliJ 下载的 Java 17 JDK (Amazon Corretto)
在终端中,运行命令:./gradlew clean build
导致以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'learn-spring-framework'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.1
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1 was found. The consumer was configured to find a runtime of a library compatible with …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 SpringBoot 版本从 2.1.1 升级到 2.7.x (2.7.5){Java 版本 - 17},当我尝试运行我的应用程序时,收到以下错误消息
引起原因:java.lang.NullPointerException:无法调用“String.contains(java.lang.CharSequence)”,因为“variable”在org.springframework.data.jpa.repository.query.QueryUtils.createCountQueryFor(QueryUtils.java: 607)在org.springframework.data.jpa.repository.query.DefaultQueryEnhancer.createCountQueryFor(DefaultQueryEnhancer.java:49)在org.springframework.data.jpa.repository.query.StringQuery.deriveCountQuery(StringQuery.java:119)在org .springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.(AbstractStringBasedJpaQuery.java:72) 在 org.springframework.data.jpa.repository.query.NativeJpaQuery.(NativeJpaQuery.java:53) 在 org.springframework.data.jpa .repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:51) 在 org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:169) 在 org.springframework.data.jpa.repository .query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:253) 在 org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93) 在 org.springframework.data.repository.core .support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:103) ... 省略 60 个常见框架
这是我的依赖项:
implementation 'org.springframework.boot:spring-boot:2.7.5'
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-parent:2.7.5')
implementation('org.springframework:spring-jdbc')
implementation('org.springframework:spring-orm')
implementation('org.springframework:spring-core')
implementation('org.springframework:spring-beans')
implementation('org.springframework:spring-webmvc')
implementation('org.springframework:spring-web')
implementation('org.springframework:spring-context')
testImplementation 'org.springframework:spring-test:5.3.25'
compileOnly group: 'javax.servlet', name: 'servlet-api', version: '2.5'
runtime("org.springframework.boot:spring-boot-properties-migrator")
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.56'
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.6.5.Final'
implementation 'org.springframework.cloud:spring-cloud-context:3.1.0'
implementation …Run Code Online (Sandbox Code Playgroud) nullpointerexception spring-data-jpa jpa-2.1 spring-boot java-17
Android studio Flamingo 2022.2.1与Android Gradle 插件 8.0.0与
kotlin = "1.8.20"
compileSdk = "33"
compileSdkExtension = "5"
buildToolsVersion = "33.0.2"
targetSdk = "33"
jvmTarget = "17"
kotlinJvmTarget = "17"
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此消息?
我们建议使用较新的 Android Gradle 插件来使用compileSdk = 33
此 Android Gradle 插件 (8.0.0) 经过测试,最高可达compileSdk = 33。
强烈建议您更新项目以使用已使用compileSdk = 33进行测试的较新的Android Gradle插件。
如果您已经在使用最新版本的 Android Gradle 插件,则可能需要等待支持compileSdk = 33 的新版本可用。
要抑制此警告,请将 android.suppressUnsupportedCompileSdk=33 添加/更新到该项目的 gradle.properties。
同步、清理、重建对我没有帮助
java-17 ×10
java ×7
android ×2
gradle ×2
spring-boot ×2
concurrency ×1
eclipse ×1
java-record ×1
jpa-2.1 ×1
locale ×1
maven ×1
maven-plugin ×1
pom.xml ×1
sealed-class ×1