我使用JDK 15.0.1并尝试保存记录。我在微流代码中有个错误。在if (declaringClass.isRecord())语句中抛出的异常文本无法在记录(预览):上获得字段偏移。
在文档中,说明自JDK 14以来就支持记录(请参阅https://manual.docs.microstream.one/data-store/faq/java-features#can-microstream-handle-records)。
if (f == null) {
throw new NullPointerException();
}
Class<?> declaringClass = f.getDeclaringClass();
if (declaringClass.isHidden()) {
throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
}
if (declaringClass.isRecord()) {
throw new UnsupportedOperationException("can't get field offset on a record (preview): " + f);
}
return theInternalUnsafe.objectFieldOffset(f);
}我使用以下版本的微流
implementation 'one.microstream:storage.embedded:04.00.00-MS-GA'我做错什么了吗?
由衷地
发布于 2020-11-11 13:06:21
谢谢你对微流的兴趣。不幸的是,我无法从对问题的描述中找到问题所在。描述中的代码来自jdk类Unsafe.java。由于我还不能重现您的问题,所以我很快在github中完成了一个小测试项目,在github中,对于Record的基本测试是用Java进行的。https://github.com/johny2000uwb/microstream-records
public record PersonRecord(String firstName, String lastName) {
} @Test
public void saveRecordTest() {
PersonRecord personRecord = new PersonRecord("Maria", "Lukasova");
EmbeddedStorageManager storage = EmbeddedStorage.start(personRecord, location);
storage.shutdown();
PersonRecord secondRecord = new PersonRecord("Kamila", "Pazourkova");
storage = EmbeddedStorage.start(secondRecord, location);
Assertions.assertEquals("Maria", secondRecord.firstName());
}记录仍然只是预览功能,因此有必要启用它。例如,在Maven中:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>14</release> <!-- <release>13/14/15</release> -->
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</build>发布于 2022-01-20 22:07:01
https://stackoverflow.com/questions/64768801
复制相似问题