我现在正在这样做.
final CriteriaBuilder builder = ...;
final boolean flag = ...;
if (flag) {
builder.isTrue(expression);
} else {
builder.isFalse(expression);
}
Run Code Online (Sandbox Code Playgroud)
我能这样用吗?
builder.equals(expression, flag);
Run Code Online (Sandbox Code Playgroud)
这尝试不会有任何问题吗?对表达式或其他东西说null.
我想我刚刚发现两个不同的JPA实现在约束违规和回滚方面的工作方式不同.
@Test(expectedExceptions = @@.class) // CVE or RB?
public void testXXX() {
final EntityManager manager = LocalPU.createEntityManager();
try {
final EntityTransaction transaction = manager.getTransaction();
transaction.begin();
try {
manager.persist(<wrong>); // this is where CVE coming from
transaction.commit(); // this is where RB coming from
} catch (RollbackException re) {
// <---------------------------------------- hibernate here
throw re;
} catch (ConstraintViolationException cve) {
// <---------------------------------------- eclipselink here
transaction.rollback();
throw cve;
} catch (Exception e) {
transaction.rollback();
e.printStackTrace(System.err);
Assert.fail(e.getMessage());
}
} finally {
manager.close();
} …Run Code Online (Sandbox Code Playgroud) 我学习了两种创建泛型数组的方法.
一个是
@SuppressWarnings("unchecked")
static <T> T[] array1(final Class<T> elementType, final int size) {
return (T[]) Array.newInstance(elementType, size);
}
Run Code Online (Sandbox Code Playgroud)
另一个是
static <T> T[] array2(final Class<T[]> arrayType, final int size) {
return arrayType.cast(Array.newInstance(arrayType.getComponentType(), size));
}
Run Code Online (Sandbox Code Playgroud)
哪个更好?它们是相同的(内部)吗?有没有什么事实错?
如何使用Bouncy Castle生成对称密钥?无论PrivateKeyFactory和PublicKeyFactory似乎与AsymmetricKeyParameter.
我不想知道任何JCA/JCE API - 相反,我只对Bouncy Castle特定的API感兴趣.
可以(应该)我只生成一个随机字节?
假设我有一个注释。
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
int value() default 1;
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以获取1使用反射之类的价值吗?
我延长了QWebEngineView.
#ifndef MYQWEBENGINEVIEW_H
#define MYQWEBENGINEVIEW_H
#include <QWebEngineView>
class MyQWebEngineView : public QWebEngineView
{
public:
MyQWebEngineView(QWidget *parent = 0);
~MyQWebEngineView();
protected:
virtual void paintEvent(QPaintEvent *);
};
#endif // MYQWEBENGINEVIEW_H
Run Code Online (Sandbox Code Playgroud)
但我不能被paintEvent(QPaintEvent *)召唤.
#include "myqwebengineview.h"
#include <QPaintEvent>
#include <QPainter>
#include <QWebEngineView>
#include <QWidget>
MyQWebEngineView::MyQWebEngineView(QWidget *parent):QWebEngineView(parent)
{
qDebug() << "MyQWebEngineView(" << parent << ")";
qDebug() << "Qt::WA_PaintOnScreen: " << testAttribute(Qt::WA_PaintOnScreen);
//setAttribute(Qt::WA_PaintOnScreen, true);
}
MyQWebEngineView::~MyQWebEngineView()
{
}
void MyQWebEngineView::paintEvent(QPaintEvent * event)
{
qDebug() << "paintEvent(" << event << ")";
QWebEngineView::paintEvent(event);
//QWidget::paintEvent(event); …Run Code Online (Sandbox Code Playgroud) 用a Stream<T>和a Comparator<? super T>,
Stream<T> s;
Comparator<? super T> c;
Run Code Online (Sandbox Code Playgroud)
是
s.sorted(c).findFirst();
Run Code Online (Sandbox Code Playgroud)
等于相当于
s.min(c);
Run Code Online (Sandbox Code Playgroud)
?
我是leiningen的新手.
当我试图执行以下时,
$ lein clean jar
Run Code Online (Sandbox Code Playgroud)
我有
Wrong number of arguments to clean task.
Expected []
$
Run Code Online (Sandbox Code Playgroud)
如何在一个命令中执行多个任务?
我知道这Pageable来自spring-data-域名.
有没有直接使用任何优雅的方式org.springframework.data.domain.Pageable在@RestController?
我试过跟随.
@RequestMapping(method = RequestMethod.GET,
path = "pageable",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Pageable> readPageable(@NotNull final Pageable pageable) {
return ResponseEntity.ok(pageable);
}
Run Code Online (Sandbox Code Playgroud)
结果不是我的预期.
...: ~ $ curl -X GET --header 'Accept: application/json' 'http://localhost:8080/.../pageable?limit=1&offset=1' | python -mjson.tool
...
{
"offset": 0,
"pageNumber": 0,
"pageSize": 20,
"sort": null
}
Run Code Online (Sandbox Code Playgroud) 我试图扩展,TemporalAdjuster以便看起来像,
public interface TypedTemporalAdjuster<T extends Temporal & Comparable<? super T>> {
T adjustInto(T temporal);
}
Run Code Online (Sandbox Code Playgroud)
当我试图直接扩展基接口时,
public interface TypedTemporalAdjuster<T extends Temporal & Comparable<? super T>>
extends TemporalAdjuster {
T adjustInto(T temporal);
}
Run Code Online (Sandbox Code Playgroud)
我收到了一个错误.
... java:name clash:...有相同的擦除,但都没有覆盖另一个
有没有办法做到这一点?
到目前为止,我做到了.
public interface TypedTemporalAdjuster<T extends Temporal & Comparable<? super T>> { //extends TemporalAdjuster {
static <T extends Temporal & Comparable<? super T>> TypedTemporalAdjuster<T> of(
final Class<T> temporalClass, final TemporalAdjuster temporalAdjuster) {
return temporal -> temporalClass.cast(temporalAdjuster.adjustInto(temporalClass.cast(temporal)));
}
T adjustInto(T temporal);
}
Run Code Online (Sandbox Code Playgroud) java ×5
generics ×2
java-8 ×2
jpa ×2
aes ×1
annotations ×1
arrays ×1
bouncycastle ×1
clojure ×1
criteria ×1
criteria-api ×1
cryptography ×1
eclipselink ×1
hibernate ×1
java-stream ×1
key ×1
leiningen ×1
pagination ×1
qt ×1
qtwebengine ×1
reflection ×1
spring ×1
spring-mvc ×1
spring-rest ×1