我可以给出一个由单个值组成的结果集,例如1,如下所示:
SELECT 1 as column;
Run Code Online (Sandbox Code Playgroud)
它给了我结果集:
column
------
1
Run Code Online (Sandbox Code Playgroud)
但是我有一个表示为字符串的此类值的列表,(1, 4, 7, ...)我需要生成以下结果集:
column
------
1
4
7
.
.
.
Run Code Online (Sandbox Code Playgroud)
我试过了,SELECT * FROM (1, 4, 7)但没有用。我也尝试过,SELECT 1, 4, 7但它产生以下结果集:
col1 col2 col3
1 4 7
Run Code Online (Sandbox Code Playgroud)
这不是我想要的。
我有实体:
@Entity
@Table(name = "message")
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "email")
private String email;
@Column(name = "subject")
private String subject;
@Column(name = "content")
private String content;
@Column(name = "html")
private String html;
@Column(name = "status")
private Integer status;
@Column(name = "creation_date")
private Date creationDate;
@Column(name = "send_date")
private Date sendDate;
//GET, SET
}
Run Code Online (Sandbox Code Playgroud)
该表message对创建日期列有以下定义:
creation_date timestamp without time zone NOT NULL DEFAULT now()\
Run Code Online (Sandbox Code Playgroud)
作为结论,当我没有设置特定值时creation_date,hibernate 将生成一个如下所示的查询: …
比较创建大型ArrayList与intialCapacity我发现它;比没有一个创建它慢.这是我编写的用于衡量它的简单程序:
long start2 = System.nanoTime();
List<Double> col = new ArrayList<>(30000000); // <--- Here
for (int i = 0; i < 30000000; i++) {
col.add(Math.sqrt(i + 1));
}
long end2 = System.nanoTime();
System.out.println(end2 - start2);
System.out.println(col.get(12411325).hashCode() == System.nanoTime());
Run Code Online (Sandbox Code Playgroud)
新的平均结果ArrayList<>(30000000):6121173329
新的平均结果ArrayList<>():4883894100
在我的机器上.我认为创建一次大型数组会更快,而不是一旦我们超出当前底层数组的容量就重新创建它ArrayList.最终我们应该最终得到大于或等于的数组大小30000000.
我认为这是优化,但实际上是悲观.为什么?
如果类型变量是通配符,那么该方法的返回类型是什么?
public class MyClass{ }
List<? extends MyClass> nms = new ArrayList<MyClass>();
nms.add(new MyClass()); //compilation error
MyClass n = nms.get(0); //compiles fine
Run Code Online (Sandbox Code Playgroud)
东西是返回类型get不是纯MyClass类型.Eclipse告诉我它CAP#2和add方法的参数在CAP#1哪里CAP#2是subtypeof MyClass,但MyClass不是subtypeof CAP#1?
所以,我对编译器捕获类型在类层次结构中的位置感兴趣?如果我们创造
public class MySubClass extends MyClass{ }
Run Code Online (Sandbox Code Playgroud)
将CAP#2是哪一个子类型MySubClass?
我有以下两个类:
public class A{
private String s;
public A(String s){
this.s = s;
}
}
public class B{
private static final String STR = "String";
public void doAction(){
A a = new A(STR); //Does it look really wierd?
}
}
Run Code Online (Sandbox Code Playgroud)
我从未将静态final字段作为构造函数参数传递,因此它是否会导致潜在的错误?我们应该避免它,或者我们可以做到这一点,如果它看起来简洁.
我只想reduce在a中找到最小值List<Integer>.这是我最初的想法:
List<Integer> lst;
//init
//assuming it's not empty
lst.stream().reduce(lst.get(0), (x, y) -> x.compareTo(y) <= 0 ? x : y);
Run Code Online (Sandbox Code Playgroud)
该
identity值必须是累加器函数的标识.这意味着对于所有t,accumulator.apply(identity, t)等于t.累加器函数必须是关联函数.
因此,identity保留累加器合约的唯一可能值(x, y) -> x.compareTo(y) <= 0 ? x : y是最大值.因此我们有一些鸡蛋问题.
如何解决它保留所有合同?
我试图理解定义Some::flatten并遇到麻烦.以下是它的外观:
def flatten[B](implicit ev: A <:< Option[B]): Option[B] =
if (isEmpty) None else ev(this.get)
Run Code Online (Sandbox Code Playgroud)
我不明白的意思A <:< Option[B].什么<:<意思?
在下面最简单的示例中,我没有编译错误:
object App {
def main(args: Array[String]) = {
test[Int]()
}
def test[T <: Int : ClassTag]() = println(implicitly[ClassTag[T]])
}
Run Code Online (Sandbox Code Playgroud)
程序打印Int. ClassTag[T]但我不明白为什么可以找到类型的对象来implicitly[ClassTag[T]]调用?我所做的唯一一件事就是提供泛型类型参数。它从哪里来ClassTag[Int]?
Java 8
我有一个很大的集合(大约100M元素),我需要迭代它并做一些动作.有两种选择:
迭代一次并完成整个工作(这会使代码复杂化)
迭代它两次,在第一次迭代中完成一半的工作,在第二次迭代中休息(这将显着简化代码)
所以,我认为迭代不是那么昂贵,并写了一个简单的例子来衡量它(我不经常写基准,因此它可能看起来有点傻):
Collection<Double> col = new LinkedList<>();
for(int i = 0; i < 30000000; i++){
col.add(Math.sqrt(i + 1));
}
long start1 = System.nanoTime();
Double res = 0.0;
for(Double d : col){
res += d + d;
}
long end1 = System.nanoTime();
System.out.println(end1 - start1);
System.out.println("=================================");
long start2 = System.nanoTime();
Double res2 = 0.0;
for(Double d : col){
res2 += d;
}
for(Double d : col){
res2 += d;
}
long end2 = System.nanoTime();
System.out.println(end2 - start2); …Run Code Online (Sandbox Code Playgroud) 我在官方网站上阅读了有关调度员的文档。但目前还不清楚什么调度员是野兽。例如,它可以配置如下:
my-thread-pool-dispatcher {
# Dispatcher is the name of the event-based dispatcher
type = Dispatcher
# What kind of ExecutionService to use
executor = "thread-pool-executor"
# Configuration for the thread pool
thread-pool-executor {
# minimum number of threads to cap factor-based core number to
core-pool-size-min = 2
# No of core threads ... ceil(available processors * factor)
core-pool-size-factor = 2.0
# maximum number of threads to cap factor-based number to
core-pool-size-max = 10
}
# Throughput defines the …Run Code Online (Sandbox Code Playgroud)